How can we fire a simple SQL Statement using ADO?
- 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.
How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures?
ADO.NET provides the SqlCommand object, which provides the functionality of executing stored procedures. In the command type we need to provide the command type as stored procedure as shown in the below code snippet.
SqlCommand objCommand = new
How can we force the connection object to close after my data reader is closed?
Command method Execute reader takes a parameter called as Command Behavior wherein we can specify saying close connection automatically after the Data reader is close.
I want to force the data reader to return only schema of the data store rather than data.
See following video on ADO.NET Connection pooling: -