vb.net错误 - >填充:SelectCommand.Connection属性尚未初始化

时间:2013-09-21 10:34:18

标签: .net sql-server vb.net

 Me.SqlConnection1.ConnectionString = dbconn.ConnectionString

    Me.SqlDataAdapter1.SelectCommand.CommandText = "Select * From repSMI where Date Between '" & formSMI.DateTimePicker1.Value & "' and '" & formSMI.DateTimePicker2.Value & "'"
    Dim DsetSMI1 As New DataSet
    Me.DsetSMI1.Clear()
    Me.SqlDataAdapter1.Fill(Me.DsetSMI1, "repSMI")


    Dim x As New repSMI
    x.SetDataSource(Me.DsetSMI1)
    Me.CrystalReportViewer1.ReportSource = x
    Me.CrystalReportViewer1.Refresh()

可能的解决办法是什么?谢谢!

1 个答案:

答案 0 :(得分:0)

您没有打开连接。而不是将它分配给你的命令。尝试添加

Me.SqlDataAdapter1.SelectCommand.Connection = Me.SqlConnection1
Me.SqlConnection1.Open();

Me.SqlConnection1.ConnectionString = dbconn.ConnectionString

填写DataSet后不要忘记关闭它。