• +91 9723535972
  • info@interviewmaterial.com

Ado.net Interview Questions and Answers

Question - What you understand by ExecuteNonQuery Method?

Answer -

The ExecuteNonQuery method is used to execute the command and return the number of rows affected.

The ExecuteNonQuery method cannot be used to return the result set.

Snippets working with ExecuteNonQuery

public void CallExecuteNonQuery()
{
    SqlConnection conn = new SqlConnection();
    conn.ConnectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
    try
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "DELETE FROM EMP WHERE DEPTNO = 40";
        cmd.CommandType = CommandType.Text;
        conn.Open();
        Int32 RowsAffected = cmd.ExecuteNonQuery();
        MessageBox.Show(RowsAffected + " rows affected", "Message");
        cmd.Dispose();
        conn.Dispose();
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners