asp.net.ph

SqlCommandBuilder Constructor ( SqlDataAdapter )

System.Data.SqlClient Namespace   SqlCommandBuilder Class


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

[ VB ]
Public Sub New ( _
   ByVal adapter As SqlDataAdapter _
)

[ C# ]
public SqlCommandBuilder (
   SqlDataAdapter adapter
);

[ C++ ]
public: SqlCommandBuilder (
   SqlDataAdapter* adapter
);

[ JScript ]
public function SqlCommandBuilder (
   adapter : SqlDataAdapter
);

Parameters

adapter
The name of the SqlDataAdapter.

Remarks

The SqlCommandBuilder registers itself as a listener for RowUpdating events that are generated by the SqlDataAdapter specified in this property.

When you create a new instance SqlCommandBuilder, any existing SqlCommandBuilder associated with this SqlDataAdapter is released.

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.

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   SqlCommandBuilder Constructor Overload List 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