sqlcommand builder

 

 

-->sqlcommandbuilder is a standalone class.

  • it is derived from system.data.sqlclient.sqlcommandbuilder.
  • creating a commandbuilder object is pretty simply.you pass a data adapter as an argument of the commandbuilder constructor.forexample://create a command builder object

                  sqlcommandbuilder builder=new sqlcommandbuilder(adapter);

  • constructor:

constructor

parameter

diacription

sqlcommandbuilder

()

the default constructor initializes all fields to there dafault values.

sqlcommandbuilder

(sqldataadapter adapter)

initializes a new instance of the sqlcommandbuilder class with the associated sqldataadapter object.

  • method:
  •  

o                                getdeletecommand

()

returns the automatically genrated transact-sql statement required to perform deletion on the database when an application calls update on the sqldataadapter

getinsertcommand

()

returns the automaticallygenrated transact-sql statement required to perform inserts on the database when an application calls update on the sqldataadapter

getupdatecommand

()

returns the automaticallygenrated transact-sql statement required to perform updates on the database when an application calls update on the sqldataadapter

  • example: 
  • next you construct the commandbuilder by passing the dataadapter into its constructor. the act of creating the commandbuilder automatically cause the UPDATE,INSERT,and DELETE commands to be genrated for the adapter: 
  • sqlcommandbuilder builder=new sqlcommandbuilder(adapter);

 

  • next,fill the dataset using the adapter and create an instance of the employee datatable from the dataset:

                     //create a dataset object
                      dataset ds=new dataset("employee set");
                        adapter.fill(ds,"employees");

  • now insert a new datarow into the datatable in memory  and  popular a row with your desired value using datatable''''sAddnew
  • method.after that you call the datarowcollection.Add method to add the row the datatable:

                  //create a data table object and add a new row

                 datatable employee table=ds.tables["employees"];

                 datarow row=employeetable.newrow();

                 row["firstname"]="rodney";

                 row["lastname"]="dangerfield";

                 row["title"]="comedian";

                 employeetable.rows.add(row);

  • finally you call dataadapter''''s update method to update the datatable change to the data source:

               //update data adapter

               adapter.update(ds,"employees");

 


Average Rating (0)
by urvashi   thakor  in VB.Net  on 5/4/2015 5:50:40 AM  


Post Your Comment
*