-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