VB 向SQL Sever中写入数据问题,求解答

weixin_43219579 weixin_43219579 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我是初学,需要将读取数据写入到数据库中,如下代码,报错
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
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
weixin_43219579
应用实例 27,579 成员 68,540 内容