| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SqlDataAdapter ClassSystem.Data.SqlClient Namespace Represents a set of data commands and a database connection which are used to fill the DataSet and update an SQL Server™ database.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Visibility | Name | Value Type | Accessibility |
|---|---|---|---|
| public | DeleteCommand | SqlCommand | [ Get , Set ] |
| public | InsertCommand | SqlCommand | [ Get , Set ] |
| public | SelectCommand | SqlCommand | [ Get , Set ] |
| public | UpdateBatchSize | Int32 | [ Get , Set ] |
| public | UpdateCommand | SqlCommand | [ Get , Set ] |
| Visibility | Name | Parameters | Return Type |
|---|---|---|---|
| protected | AddToBatch | ( IDbCommand command ) | Int32 |
| protected | ClearBatch | ( ) | Void |
| protected | CreateRowUpdatedEvent | ( DataRow dataRow , IDbCommand command , StatementType statementType , DataTableMapping tableMapping ) | RowUpdatedEventArgs |
| protected | CreateRowUpdatingEvent | ( DataRow dataRow , IDbCommand command , StatementType statementType , DataTableMapping tableMapping ) | RowUpdatingEventArgs |
| protected | ExecuteBatch | ( ) | Int32 |
| protected | GetBatchedParameter | ( Int32 commandIdentifier , Int32 parameterIndex ) | IDataParameter |
| protected | GetBatchedRecordsAffected | ( Int32 commandIdentifier , Int32& recordsAffected , Exception& error ) | Boolean |
| protected | InitializeBatching | ( ) | Void |
| protected | OnRowUpdated | ( RowUpdatedEventArgs value ) | Void |
| protected | OnRowUpdating | ( RowUpdatingEventArgs value ) | Void |
| protected | TerminateBatching | ( ) | Void |
| Multicast | Name | Type |
|---|---|---|
| multicast | RowUpdated | SqlRowUpdatedEventHandler |
| multicast | RowUpdating | SqlRowUpdatingEventHandler |
The SqlDataAdapter serves as a bridge between SQL Server™ and a DataSet, providing the interface for retrieving and saving the data. Using the appropriate Transact-SQL statements against the data source, the SqlDataAdapter provides this bridge by mapping:
SqlDataAdapter is used in conjunction with SqlConnection and SqlCommand to increase performance when connecting to a Microsoft SQL Server™ database. To access other data sources, use OleDbDataAdapter along with its associated OleDbConnection and OleDbCommand.
The SqlDataAdapter also includes the SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings properties for facilitating the loading and updating of data.
A new instance of SqlDataAdapter can be constructed in four ways. For a list of the different versions and the parameters that can be used with each, see the SqlDataAdapter constructor.
The following example shows using an SqlDataAdapter to fill a DataSet with records retrieved from a data source. Here, the entire logic is encapsulated within a Page_Load event handler that essentially:
string html;
protected void Page_Load ( Object Src, EventArgs e ) {
// set up the connection
SqlConnection myConn = new SqlConnection (
"server=localhost; trusted_connection=yes; database=northwind" );
// set up the query
SqlDataAdapter myAdapter = new SqlDataAdapter ( "SELECT * FROM nw_Customers", myConn );
// instantiate dataset object
DataSet myData = new DataSet ( );
// fill with query results
myAdapter.Fill ( myData, "Customers" );
// display dataset contents into html table
// first open the table and set up the table headers
html += "<table cellspacing=1 class='data' width=80%>";
html += "<tr>";
html += "<th>Customer ID</th>";
html += "<th>Company Name</th>";
html += "</tr>";
// loop thru the dataset
foreach ( DataRow Customer in myData.Tables [ "Customers" ].Rows ) {
html += "<tr>";
html += "<td>" + Customer [ "CustomerID" ].ToString ( ) + "</td>";
html += "<td>" + Customer [ "CompanyName" ].ToString ( ) + "</td>";
html += "</tr>";
}
// close the table
html += "</table>";
}
| ||
| C# | VB | |
SqlConnection SqlCommand DataSet DataTable
Check out related books at Amazon
© 2000-2008 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 aspxtreme