This article has been excerpted from book "A Programmer's Guide to ADO.NET in C#".
DataAdapter Properties
As you start working data adapters, you need take a Quick looks at data adapter properties and methods. The DataAdapter has properties of type Command, which represent the ways it can query, insert, delete, and update the database.
These properties are of type OleDbCommand.
Table 5-28 describes OleDbDataAdapter class properties.
Table 5-28 describes ole Db DataAdapter properties
PROPERTY |
DESCRIPTION |
DeleteCommand |
Represents a DELETE statement or stored procedure for deleting records from the data source |
InsertCommand |
Represents an INSERT statement or stored procedure for inserting a new record to The data source |
SelectCommand |
Represents a SELECT statement or stored procedure can be used to select records from a data source |
UpdateCommand |
Represents an UPDATE statement or stored procedure for Updating recording in a data source |
TableMappings |
Represents a collection of mappings between actual data source table and a DataTable object |
Table 5-29 shows these command properties and their examples.
Table 5-29. OleDbDataAdapter Command Properties with Examples
PROPERTY |
EXAMPLE |
SelectCommand |
cmd.SelectCommand.CommandText = "SELECT * FROM Orders ORDER BY Price"; |
DeleteCommand |
TheDataSetCommand.DeleteCommand.CommandText = "DELETE FROM orders WHERE LastName = 'Smith' "; |
InsertCommand |
TheDataSetCommand.InsertCommand.CommandText = "INSERT INTO Orders VALUE (25, 'Widget1', 'smith')"; |
UpdateCommand |
TheDataSetCommand.UpdateCommand.CommandText = "UPDATE Orders SET ZipCode = '34956' WHERE OrderNum = 14"; |
Data Adapter Methods
The DataAdapter class provides many useful methods. For instance, the FILL method of the DataAdapter fills data from a data adapter to the DataSet object, and the Update method stores data from a DataSet object to the data source.
Table 5-30. The ole Db Data Adapter methods
METHOD |
DESCRIPTION |
Fill |
This method fills data records from a DataAdapter to a DataSet object. |
FillSchema |
This method adds a DataTable to a DataSet. |
GetFillParameters |
This method retrieves parameters that are used when a SELECT statement is executed. |
Update |
This method stores data from a data set to the data source. |
Conclusion
Hope this article would have helped you in understanding DataAdapter Properties and Methods in ADO.NET. See my other articles on the website on ADO.NET.
|
This essential guide to Microsoft's ADO.NET overviews C#, then leads you toward deeper understanding of ADO.NET. |