jomachi jomachi - 1 year ago 91 Question

How can I change this code to SqlConnection?

Can anyone change this code to


Dim Db As ADODB.Connection
Dim rs As ADODB.Recordset

Set Db = New ADODB.Connection
Db.ConnectionString = GetConnectString & AppPath & "schedule.mdb"
Call Db.Open
Set rs = New ADODB.Recordset
Set rs = Db.Execute("select * from tbl_Schedule where StartDate = #1/1/2002#")

While Not rs.EOF
Call Me.Schedule1.ScheduleItems.Add("", #1/1/2002#, rs!StartTime, _
rs!Length, rs!Description, "")
Call rs.MoveNext

Answer Source

Please find the below snippet which will helps you to get data from sql database. You can alter the script with your values. Import System.Data.SqlClient namespace to work with SqlConnection

Dim connection As New SqlConnection("Server=.\sqlexpress;Integrated   security=sspi;database=Automation")
Dim query As String = "Select * from Heads"
If connection.State = ConnectionState.Closed Then connection.Open()
   Using cmd As New SqlCommand(query, connection)
        Dim reader As SqlDataReader = cmd.ExecuteReader
        While reader.Read
        End While
   End Using
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download