SiteMap  | About    

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.

using System;
using System.Windows.Forms;
using System.Data.SqlClient; 

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        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 ! ");
} (C) 2015    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.