- First imports the namespace “System.Data.SqlClient”.
- Create a connection object and call the “Open” function.
With objConnection
.Connection String = strConnectionString
.Open()
EndWith
- Create the command object with the SQL. Also, assign the created connection object to command object and execute the reader.
ObjCommand = New SqlCommand
(“Select First Name from Employees”)
With objCommand
.Connection = objConnection
Breeder = .Execute Reader ()
EndWith
- You can then loop through the reader object to read the data.
Do while objReader.Read ()
lstData.Items.Add (objReader.Item (“First Name”))
Loop
- Do not forget to close the connection object.