command builder with example

Posted by Rajasekhar0544 under Interview Questions on 9/7/2012 | Points: 10 | Views : 1294 | Status : [Member] | Replies : 2
hi,

I need to know about command builder object and its commands in detail. Provide me some examples




Responses

Posted by: Ranjeet_8 on: 9/8/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down

It is a defined by System.Data.SqlClient namespace and is used to generate commands(insert,delete,update) that can be used
to reflect DataSet changes back to a sql server database
Update method of SqlDataAdapter uses the SqlCommandBuilder's commands
to reflect DataSet changes back to a sql server database.

example:

//save a record in a database using the Update method of SqlDataAdapter
using System.Data;
using System.Data.SqlClient;

class dd
{
static void Main()
{
SqlConnection cn=new SqlConnection("server=.;uid=sa;pwd=1234;database=employee");
SqlDataAdapter da=new SqlDataAdapter("select * from emp",cn);
DataTable dt=new DataTable();
da.Fill(dt);
//emp has 2 columns known as eno and ename.

//Initialize the SqlCommandBuilder.
SqlCommandBuilder cd=new SqlComandBuilder(da);

//create a DataRow
DataRow dr=dt.NewRow();
dr["eno"]=100;
dr["ename"]="king";
//the row is temporarily saved
dt.Rows.Add(dr);

//save the Row permanently
da.Update(dt);

}
}


Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jimmyhelu on: 9/8/2012 [Member] Starter | Points: 25

Up
0
Down
So I've used SQL Connection, DataAdapter, and CommandBuilder commands. I did notice that ... I have added my example code below

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response