Can we use ExecuteNonQuery method for Select statement?

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

No,we can not use,as ExecuteNonQuery method is only used for DML operations like Insert,Update and Delete operations.
As it only returns an integer value.

We can understand it by an example:-

int row_affected = 0;

SqlConnection con = new SqlConnection("write your connection name");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Update employee_master set employee_name = 'Vishal' where employee_id = 1 and status = 'AA'";
cmd.Connection = con;

row_affected = cmd.ExecuteNonQuery();

if (row_affected > 0)
//message record successfully updated.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response