ADO.NET

ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples

Examples

Use of CommandBuilder
Previous Home Next

CommandBuilder builds “Parameter” objects automatically and SqlCommandBuilder object to automatically create the DeleteCommand, the InsertCommand, and the UpdateCommand properties of the SqlCommand object for a SqlDataAdapter object,

Insert Data using SqlCommandBuilder
using System;
using System.Data;
using System.Data.SqlClient;
class stringbuildinginsert
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection(
"server=(local)\\SQLEXPRESS;database=Emp;
          Integrated Security=SSPI;");
SqlDataAdapter sda = new SqlDataAdapter
("SELECT ID, FirstName, LastName FROM Employee", con);
SqlCommandBuilder Cmdb = new SqlCommandBuilder(sda);
DataSet ds = new DataSet();
sda.Fill(ds);
DataRow drow = ds.Tables[0].NewRow();
drow["ID"] = 200;
drow["FirstName"] = "Kamal";
drow["LastName"] = "Mishra";
ds.Tables[0].Rows.Add(MyRow);
sda.Update(ds);
}
}

 

Delete Data using SqlCommandBuilder
using System;
using System.Data;
using System.Data.SqlClient;
class stringbuildinginsert
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection
("server=(local)\\SQLEXPRESS;database=Emp;Integrated 
Security=SSPI;");
SqlDataAdapter sda = new SqlDataAdapter
("SELECT ID, FirstName, LastName FROM Employee", con);
SqlCommandBuilder Cmdb = new SqlCommandBuilder(sda);
DataSet ds = new DataSet();
sda.Fill(ds);
DataColumn[] dc = new DataColumn[1];
dc[0] = ds.Tables[0].Columns[0];
dst.Tables[0].PrimaryKey = dc;
DataRow drow = MyDataSet.Tables[0].Rows.Find(1);
drow.Delete();
sdar.Update(ds);
}
}
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback:
>