I have have tried this and now my program is just freezing. Here is the code maybe you can see if i am doing something wrong here
Imports System.Data.SqlClient
PublicClass Add_Job
Private ConnString AsString
PrivateSub Add_Job_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
ConnString = "Server=localhost;Database=MyData"
EndSub
PublicSub ReadMyData(ByVal myConnString AsString)
Dim mySelectQuery AsString = "SELECT ProductId, Product FROM Product_lst"
Dim myConnection AsNew SqlConnection(myConnString)
Dim myCommand AsNew SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()
Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1)))
EndWhile
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
myConnection.Close()
EndSub'ReadMyData
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ReadMyData(ConnString)
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
EndSub
EndClass