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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18931603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:10:17  来源:igfitidea点击:

vb.net error -->Fill: SelectCommand.Connection property has not been initialized

.netsql-servervb.net

提问by jerahmeel

 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()

what would be the possible fix for this? thanks!

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

采纳答案by Yuriy Galanter

You're not opening your connection. And not assigning it to your command. Try adding

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

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

after

Me.SqlConnection1.ConnectionString = dbconn.ConnectionString

Don't forget to close it after DataSet is filled.

不要忘记在DataSet 填满后关闭它。