Chapter 19. The Command Class

The Command class is provided by all standard ADO.NET providers, and it almost always encapsulates a SQL statement or a stored procedure call that can be executed against a data source. Command objects can retrieve rows; directly insert, delete, or modify records; calculate totals and averages; alter the structure of a database; or fill a disconnected DataSet when used with a DataAdapter .

At a bare minimum, every Command must reference a Connection object, which it uses to communicate with the data source and define a few key properties, such as CommandText (the stored procedure or embedded SQL command) and CommandType . The Command class is provided in several provider-specific varieties, including SqlCommand and OleDbCommand .

To execute a Command , you use one of the Command object methods , including ExecuteNonQuery( ) , ExecuteReader( ) , and ExecuteScalar( ) , depending on the type of Command . Occasionally, a provider may define an additional method, such as the ExecuteXmlReader( ) method offered by the SQL Server provider, which retrieves query results as an XML document. Other than this discrepancy, the Command objects provided by the core set of ADO.NET providers are virtually identical.



ADO. NET in a Nutshell
ADO.NET in a Nutshell
ISBN: 0596003617
EAN: 2147483647
Year: 2005
Pages: 415

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net