Answer: 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