我正在努力使用一些SQLite到VB.net代碼。我正在使用sharpdevelop 4.0來嘗試使用SQLiteadmin連接到SQLite數據庫。我已經設置好了,只需要幫助他們在主要負載時連接到彼此。我已經把代碼放在mainform中(見下文)數據庫被稱爲「KCB.db3」。當我點擊按鈕時,我收到一條錯誤消息,指出連接已關閉。我做錯了什麼?在sharpdevelop中的SQLite連接4
Dim SQLconnect As New System.Data.SqlClient.SqlConnection
Dim SQLcommand As System.Data.SqlClient.SqlCommand
Dim SQLreader As System.Data.SqlClient.SqlDataReader
Sub Button1Click(sender As Object, e As EventArgs)
'Procedure to extract records from People table in Contacts SQLite database file
'Create an SQL command
SQLcommand = SQLconnect.CreateCommand
'Create SQL statement
SQLcommand.CommandText = "SELECT * FROM Staff"
'Extract data
SQLreader = SQLcommand.ExecuteReader()
While SQLreader.Read()
'Add record to listbox
msgbox(SQLreader("Staff_ID"))
msgbox(SQLreader("Staff_Surname"))
msgbox(SQLreader("Staff_First_Name"))
End While
'Clear SQL command buffer
SQLcommand.Dispose()
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
SQLconnect.ConnectionString = "data source = KCD.db3"
SQLconnect.Open()
End Sub
我希望有人可以幫助!謝謝
我不明白是什麼問題? –
當我點擊按鈕時,我收到一條錯誤消息,指出連接已關閉。需要連接 –
在你的SQL命令中,你需要添加連接。 –