我是初學,需要將讀取資料寫入到資料庫中,如下代碼,報錯
Could not resolve this reference. Could not locate the assembly "System.Data.SqlClient". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Type 'System.Data.SqlClient.SqlConnection' is not defined.
Type 'System.Data.SqlClient.SqlCommand' is not defined.
Type 'System.Data.SqlClient.SqlDataReader' is not defined.
請幫忙看一下哪里有問題
Try
'Dim stConnectionString As String = "Data Source=192.168.0.250\sql;" & "Initial Catalog=testDB;" & "Integrated Security=False;" & "User Id =admin;" & "Password =123;" & "Connection Timeout=5"
Dim cSqlConnection As New System.Data.SqlClient.SqlConnection(stConnectionString)
cSqlConnection.Open()
MessageBox.Show("SQL Opened")
Dim hCommand As New System.Data.SqlClient.SqlCommand()
Dim sr As System.Data.SqlClient.SqlDataReader
hCommand = cSqlConnection.CreateCommand()
hCommand.CommandTimeout = 20
hCommand.CommandText = "SELECT bbbbb, ccccc, ddddd FROM shohin where aaaaa='" & TextBox1.Text & "'"
'Dim sr As SqlDataReader = hCommand.ExecuteReader()
sr = hCommand.ExecuteReader()
hCommand.Dispose()
'// 結果取得&畫面表示
While sr.Read()
BtTextBox_2.Text = sr.Item(0)
BtTextBox_3.Text = sr.Item(1)
BtTextBox_4.Text = sr.Item(2)
End While
cSqlConnection.Close()
MessageBox.Show("SQL Closed")
cSqlConnection.Dispose()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
uj5u.com熱心網友回復:
請問編譯能通過(即生成成功)嗎?uj5u.com熱心網友回復:
編譯不能通過。uj5u.com熱心網友回復:
需先添加參考System.Data.轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/19414.html
標籤:應用實例
上一篇:C++信奧
下一篇:按位置檢索最近的兩條資料
