What does ExecuteReader return?

 Posted by vishalneeraj-24503 on 12/8/2013 | Category: ADO.NET Interview questions | Views: 2301 | Points: 40
Answer:

It returns only SqlDataReader Object.It is associated with Sqlcommand object.

For ex:-

string sql_query = "select employee_name,employee_code from employe_master where employee_id = 1 and status = 'ÁA';


//write your connection object
Sqlcommand cmd = new Sqlcommand();
cmd.connction = con;//here con is your connection object
con.open();

SqlDataReader dr = cmd.ExcuteReader();

If(dr.Read())
{
string employee_code = Convert.ToString(dr["employee_code"]);

string employee_name = Convert.ToString(dr["employee_name"]);

dr.Close();
}
con.Close();


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response