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
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
...全文
相关推荐
VB连接SQL Sever 2005数据库
"VB连接SQL Sever 2005数据库的源代码,通过VB6.0实现数据库连接,包括两种连接方式,涉及SQL Server的OLE DB提供程序和数据库连接字符串的构建。"在VB6.0中连接
VB链接SQL SEVER实例
总结来说,这个“VB链接SQL SERVER实例”资源提供了使用VB进行SQL Server数据库操作的实用示例,涵盖了连接数据库、执行SQL语句和管理数据等方面,对于学习和提升VB数据库编程技能非常有帮助
VB数据库课程设计(开发语言用VB,服务器端用的SQL Sever)
标题中的“VB数据库课程设计(开发语言用VB,服务器端用的SQL Sever)”表明这是一个基于Visual Basic(VB)编程语言进行的数据库应用系统开发的课程项目,而服务器端的数据存储和管理则采用了
一种利用VB将SQL Sever数据库数据生成excel报表的方法.pdf
在介绍如何利用VB语言将SQL Sever数据库数据生成excel报表之前,我们首先要了解几个核心知识点,包括SQL Sever数据库的基础概念、VB编程语言的应用以及Excel报表的作用和优势。
VB + SQL Sever 房屋中介管理系统
【VB + SQL Sever 房屋中介管理系统】是一个基于Visual Basic(VB)编程语言和SQL Server数据库系统的实用软件,主要用于房地产中介公司的日常业务管理。


应用实例
