Imports System.Data.SqlClient
Public Class Form1
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim dr As New SqlDataReader()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnection = New SqlConnection("Data Source=192.168.0.1;Initial Catalog=gp;User Id=ga;Password=gg")
'establishing connection. you need to provide password for sql server
'Try
myConnection.Open()
'opening the connection
myCommand = New SqlCommand("SELECT rec FROM MASTER WHERE no = '123456'", myConnection)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader()
While dr.Read()
'reading from the datareader
MessageBox.Show("rec" & dr(0).ToString())
'displaying the data from the table
End While
dr.Close()
myConnection.Close()
'Catch e As Exception
' End Try
End Sub
End Class
عند التنفيذ بيعطيني الخطا التالي :
Type 'System.Data.SqlClient.SqlDataReader' has no constructors