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();
Example:
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()
{
InitializeComponent();
}
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);
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO employeeinfo (EmpName,EmpDept,EmpLevel,EmpAddress,EmpPhone,UserName,[Password],Email)VALUES('Sudhakar','Accounts',3,'Meerpet',123456789,'Sudhakar','123','Sudhakar@gmail.com')", con);
cmd.ExecuteNonQuery();
}
}
}




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
No comments:
Post a Comment