-1
当我尝试运行此代码,我得到这个错误:vb.net数据库CommandText属性尚未初始化(system.data.dll中)
An unhandled exception of type System.InvalidOperationException' occurred in System.Data.dll
其他信息:ExecuteReader: CommandText property has not been initialized
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\database test\ikeagoed\ikeagoed\test.mdf;Integrated Security=True"
con.Open()
cmd.Connection = con
Dim reader As SqlDataReader = cmd.ExecuteReader() <<error at this line
If Not reader.HasRows Then
'the data does not exist.
MsgBox("bestaat niet!", MsgBoxStyle.Exclamation, "Add New User!")
Else
'The record exists
MsgBox("User Already Exist!", MsgBoxStyle.Exclamation, "Add New User!")
End If
con.Close()
End Sub
的一个你想读者什么样的回报?你有一个SQL查询执行? – 2015-02-09 13:37:52
阅读您用作标题的错误消息的实际字词,然后问自己初始化代码中的哪个位置(将值赋给)CommandText属性。消息中的单词使得它非常清楚问题是什么 - 它是学习真正阅读这些单词绝对必需的。它们不只是随机字母,他们实际上提供有意义的信 – 2015-04-17 00:52:26