- First imports the namespace “System.Data.SqlClient”.
- Create a connection object and call the “Open” function.
.Connection String = strConnectionString
- 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”)
.Connection = objConnection
Breeder = .Execute Reader ()
- You can then loop through the reader object to read the data.
Do while objReader.Read ()
lstData.Items.Add (objReader.Item (“First Name”))
- Do not forget to close the connection object.