Home > database >  VB to write data in SQL Sever problem, its solution
VB to write data in SQL Sever problem, its solution

Time:11-14

I am a beginner, you need to read data written to the database, the following code, an error
Could not resolve this reference. Could not locate the assembly System. The 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. The Data. SqlClient. SqlConnection' is not defined.
Type 'System. The Data. SqlClient. SqlCommand' is not defined.
Type 'System. The Data. SqlClient. SqlDataReader' is not defined.

Please have a look at where there are problems

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 the New System. The Data. SqlClient. SqlConnection (stConnectionString)
CSqlConnection. The Open ()
MessageBox. Show (" SQL the Opened ")


Dim hCommand As the New System. The Data. SqlClient. SqlCommand ()

Dim As the sr System. The Data. SqlClient. SqlDataReader

HCommand=cSqlConnection. CreateCommand ()
HCommand.Com mandTimeout=20
HCommand.Com mandText="SELECT BBBBB CCCCC, DDDDD FROM shohin where aaaaa='" & amp; TextBox1. Text & amp; "'
"
'Dim sr As SqlDataReader=hCommand. ExecuteReader ()
The sr=hCommand. ExecuteReader ()

HCommand. The Dispose ()

'//result & the picture said
While the sr. The Read ()

BtTextBox_2. Text=sr. Item (0)
BtTextBox_3. Text=sr. The Item (1)
BtTextBox_4. Text=sr. The Item (2)
End While

CSqlConnection. Close ()
MessageBox. Show (" SQL Closed ")
CSqlConnection. The Dispose ()

Catch the ex As Exception
MsgBox (ex. ToString)
End the Try

CodePudding user response:

Can compile (by generating successful)?

CodePudding user response:

A compiler cannot pass,

CodePudding user response:

Need to add reference System. The Data.
  • Related