Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     

QuestPond: Interview Questions and Answers on learning ADO.NET

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.

      With objConnection

             .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”)

With objCommand

                .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 SqlCommand("sp_Insert", objConnection);

objCommand.CommandType = CommandType.StoredProcedure;


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.

PobjDataReader = pobjCommand.ExecuteReader (CommandBehavior.CloseConnection)

I want to force the data reader to return only schema of the data store rather than data.

PobjDataReader = pobjCommand.ExecuteReader (CommandBehavior.SchemaOnly)

See following video on ADO.NET Connection pooling: -

Helpful Website Url
Share this article   |    Print    |    Article read by 2877 times
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: