ADO.Net - ExecuteNonQuery - DotNet and DataBase

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Monday, 30 July 2018

ADO.Net - ExecuteNonQuery

ExecuteNonQuery used is used to execute the queries which don't return any values. It is used to execute the manipulation queries like insert, update, delete etc. ExecuteNonQuery executes the query on command and returns the count of the number of rows affected.

int effetctedRowsCount = 0;
  Command = new SqlCommand(SqlCommand, SqlConnection);

  effetctedRowsCount = Command.ExecuteNonQuery();


using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace EmployeeTimeSheet
    public partial class InsertEmployees : Form
        public InsertEmployees()
        private void btnInsert_Click(object sender, EventArgs e)
            string connection = "Data Source=LAPTOP-xyzmno; Initial Catalog = EmployeeData; UserID=sa; Password=123456";
            SqlConnection con = new SqlConnection(connection);
            SqlCommand cmd = new SqlCommand("INSERT INTO employeeinfo (EmpName,EmpDept,EmpLevel,EmpAddress,EmpPhone,UserName,[Password],Email)VALUES('Sudhakar','Accounts',3,'Meerpet',123456789,'Sudhakar','123','')", con);

No comments:

Post a comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.