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

weixin_43219579 2020-07-03 10:47:39
我是初学,需要将读取数据写入到数据库中,如下代码,报错
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
...全文
120 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
唐诗三百首 2020-07-03
  • 打赏
  • 举报
回复
请问编译能通过(即生成成功)吗?
唐诗三百首 2020-07-03
  • 打赏
  • 举报
回复
需先添加引用System.Data.
weixin_43219579 2020-07-03
  • 打赏
  • 举报
回复
编译不能通过。

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧