asp.net.ph

SqlCommandBuilder Constructor

System.Data.SqlClient Namespace   SqlCommandBuilder Class


Initializes a new instance of the SqlCommandBuilder class.

Overload List

1. Initializes a new instance of the SqlCommandBuilder class.

2. Initializes a new instance of the SqlCommandBuilder class with the associated SqlDataAdapter object.


Example

The following example uses the SqlCommand, along with SqlDataAdapter and SqlConnection, to select rows from a data source. The example is passed an initialized DataSet, a connection string, a query string that is a Transact-SQL SELECT statement, and a string that is the name of the database table. The example then initializes an SqlCommandBuilder.

NOTE: This example uses one of the overloaded versions of the SqlCommandBuilder constructor. For other examples that may be available, see the individual overload topics.

public DataSet SelectSqlSrvRows ( DataSet myDataSet, string myConn, 
      string query, string myTableName ) {
   SqlConnection myConn = new SqlConnection ( myConn );
   SqlDataAdapter myDataAdapter = new SqlDataAdapter ( );
   myDataAdapter.SelectCommand = new SqlCommand ( query, myConn );
   SqlCommandBuilder custCB = new SqlCommandBuilder ( myDataAdapter );
   myConn.Open ( );

   DataSet myDataSet = new DataSet ( );
   myDataAdapter.Fill ( myDataSet, "Customers" );

   // code to modify data in dataset here

   // without the SqlCommandBuilder this line would fail
   myDataAdapter.Update ( myDataSet, "Customers" );
   myConn.Close ( );
}
  C# VB

See Also

SqlCommandBuilder Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph