C# ADO.NET SqlCommand - ExecuteNonQuery
The ExecuteNonQuery() is one of the most frequently used method in SqlCommand Object, and is used for executing statements that do not return result sets (ie. statements like insert data , update data etc.) .
The ExecuteNonQuery() performs Data Definition tasks as well as Data Manipulation tasks also. The Data Definition tasks like creating Stored Procedures ,Views etc. perform by the ExecuteNonQuery() . Also Data Manipulation tasks like Insert , Update , Delete etc. also perform by the ExecuteNonQuery() of SqlCommand Object.
The following C# example shows how to use the method ExecuteNonQuery() through SqlCommand Object.
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
string connetionString = null;
SqlConnection cnn ;
SqlCommand cmd ;
string sql = null;
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
sql = "Your SQL Statemnt Here";
cnn = new SqlConnection(connetionString);
cmd = new SqlCommand(sql, cnn);
MessageBox.Show (" ExecuteNonQuery in SqlCommand executed !!");
catch (Exception ex)
MessageBox.Show("Can not open connection ! ");