ADO.NET Interview questions


Total available count: 25
Subject - Microsoft Technologies
Subsubject - ADO.NET

What is the importance of ExecuteNonQuery, ExecuteReader and ExecuteScalar methods in SqlCommand?

When a SqlCommand is ready with query or stored procedure, There is a SqlCommand property is required to execute and return the result from the database.

Below are the important properties of SqlCommand,
 
1. ExecuteNonQuery
2. ExecuteReader
3. ExecuteScalar
 

1. ExecuteNonQuery: ExecuteNonQuery method returns an integer specifying the number of rows inserted, deleted or updated.

Example:
SqlCommand cmd = new SqlCommand();
cmd.ExecuteNonQuery();

2. ExecuteReader: To return the result into a SqlDataReader.

Example:
SqlCommand cmd = new SqlCommand();
SqlDataReader dr = cmd.ExecuteReader();

3. ExecuteScalar: To return a single value from the query or stored procedure.

Example:
SqlCommand cmd = new SqlCommand();
cmd.ExecuteScalar("Query or stored procedure");

 




Next 5 interview question(s)

1
What is the purpose of database transactions?
2
Explain differences between Dataset and Datareader?
3
What is the use of SqlParameter.Direction?
4
What is the full-form of ADO?
5
Is it possible to update the database by using SqlDataReader?

Comments