VB 向SQL Sever中写入数据问题,求解答
我是初学,需要将读取数据写入到数据库中,如下代码,报错
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