The Managed Providers

IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Appendix D.  ADO.NET Controls: Properties and Methods


Managed providers allow ADO.NET to interact with any type of OleDB-compliant data source. These providers are used to move data into the DataSet and its related classes, and can be used independently to modify data as well.

There are two managed providers: OleDB and SQL. The former deals with all OleDB-compliant data stores, whereas the latter deals only with SQL Server. In nearly all cases, classes in one provider correspond exactly to classes in the other; the only difference is the use of a prefix: OleDb and Sql. For instance, both providers have an class that provides lightweight access to data, respectively named OleDbDataReader and SqlDataReader.

Because of the similarities of these two providers, only the OleDb managed provider is covered here. Where there are differences in the two, a note is made.

OleDbCommand

The OleDbCommand class represents a SQL statement to be made to a data source. Table C.13 lists the properties and methods of this class.

Table C.13. Properties and Methods of the OleDbCommand Class
Property Description
CommandText The SQL statement to execute.
CommandTimeout The time limit in which the command must execute before termination.
CommandType Specifies how the CommandText property is interpreted. Can be StoredProcedure, TableDirect, or Text (default).
Connection Specifies an OleDbConnection used by this object.
DesignTimeVisible Indicates if the command object should be visible in a custom Windows Forms designer control.
Parameters Gets an OleDbParameterCollection object representing the parameters for use with this command.
Transaction The OleDbTransaction used by the command.
UpdatedRowSource The number of records affected by the command. Typically one if the command succeeds, and less than one otherwise.
Method Description
Cancel Cancels the execution of the command.
CreateParameter Creates an OleDbParameter for use with this command.
ExecuteNonQuery Executes a SQL statement that doesn't return any data.
ExecuteReader Returns an OleDbDataReader filled with the data returned from the command.
ExecuteScalar Executes the query, and returns value in the first column and first row of the returned results.
Prepare Creates a compiled version of the command.
ResetCommandTimeout Resets the CommandTimeout property to the default value.

OleDbCommandBuilder

The OleDbCommandBuilder class represents an easy way to generate commands for use against a data source. Table C.14 lists the properties and methods of this class.

Table C.14. Properties and Methods of the OleDbCommandBuilder Class
Property Description
DataAdapter The name of an OleDbDataAdapter for which the commands are generated.
QuotePrefix Specifies a prefix to use when specifying data source object names (such as tbl for tables, sp for stored procedures, and so forth).
QuoteSuffix Specifies a suffix to use when specifying data source object names.
Method Description
DeriveParameters Fills the OleDbCommand's Parameters collection with values specified in the stored procedure.
GetDeleteCommand Gets the automatically generated SQL statement to delete rows from the data source.
GetInsertCommand Gets the automatically generated SQL statement to insert rows into the data source.
GetUpdateCommand Gets the automatically generated SQL statement to update rows in the data source.
RefreshSchema Retrieves the schema of the data source.

OleDbConnection

The OleDbConnection class represents a connection to a data source. Table C.15 lists the properties, methods, and events of this class.

Table C.15. Properties, Methods, and Events of the OleDbConnection Class
Property Description
ConnectionString The string used to open a database.
ConnectionTimeout The time limit for establishing a connection to the database, after which an error will be generated.
Database The name of the database to use once the connection is established.
DataSource The name of the database to connect to.
Provider The name of the database provider.
ServerVersion A string containing the version of the server to which the client is connected.
State The current state of the connection.
Method Description
BeginTransaction Begins a database transaction. This method is overloaded.
ChangeDatabase Changes the current database to another specified value.
Close Closes the database connection.
CreateCommand Returns an OleDbCommand object to execute commands against the database.
GetOleDbSchemaTable Returns schema information from a data source specified by a GUID. (This method does not exist in the corresponding SqlConnection class.)
Open Attempts to open the connection to the database.
ReleaseObjectPool Indicates that the OleDbConnection object pooling can be cleared when the last underlying OLE DB provider is released.
Event Description
InfoMessage Occurs when the provider sends a message. Uses an OleDbInfoMessageEventArgs object for the event parameter. This object contains the following properties:

ErrorCode An HRESULT value indicating the standard error.

Errors An OleDbErrorCollection of warnings sent by the provider.

Message The full text of the error message sent from the provider.

Source The name of the object that generated the error.

StateChange Occurs when the state of the connection changes. Uses a StateChangeEventArgs for the event parameter. This object contains the following properties:

CurrentState The new state of the connection.

OriginalState The original state of the connection.

OleDbDataAdapter

The OleDbDataAdapter class represents a set of data commands and a database connection that are used to fill a DataSet. Table C.16 lists the properties, methods, and events of this class.

Table C.16. Properties, Methods, and Events of the OleDbDataAdapter Class
Property Description
DeleteCommand Returns an OleDbCommand object that contains a SQL statement for deleting data from the DataSet.
InsertCommand Returns an OleDbCommand object that contains a SQL statement for inserting data into the DataSet.
SelectCommand Returns an OleDbCommand object that contains a SQL statement for selecting data from the DataSet.
UpdateCommand Returns an OleDbCommand object that contains a SQL statement for updating data in the DataSet.
Method Description
Fill Adds or changes rows in a DataSet to match the data source. This method is overloaded.
FillSchema Adds a DataTable to the specified DataSet and configures the schema of the table. This method is overloaded.
GetFillParameters Returns an array of IDataParameter objects that are used with the SELECT command.
Update Updates the data source with the information in the DataSet using the Delete, Insert, and UpdateCommand properties. This method is overloaded.
FillError Occurs when an error is returned during a Fill operation. Uses a FillErrorEventArgs object for the event parameter. This object contains the following properties:

Continue Indicates if the operation should continue.

DataTable The DataTable being updated when the error occurred.

Errors Returns an Exception object representing the errors being handled.

Values Returns an object representing the values for the row being updated when the error occurred.

RowUpdated Occurs after an Update command has executed. Uses an OleDbRowUpdatedEventArgs object for the event parameter. This object contains the following properties:

Command Returns the OleDbCommand executed when Update is called.

Errors Returns an Exception object representing the errors that occurred.

RecordsAffected The number of records affected.

Row Gets the DataRow used by Update.

StatementType The type of SQL statement being executed.

Status An UpdateStatus object representing the status of the command.

TableMapping Gets the DataTableMapping sent with the Update command.

RowUpdating Occurs before an Update command has executed. Uses an OleDbRowUpdatingEventArgs object for the event parameter. This object contains the following properties:

Command Returns the OleDbCommand to execute when Update is called.

Errors Returns an Exception object representing the errors that occurred.

Row Gets the DataRow used by Update.

StatementType The type of SQL statement to execute.

Status An UpdateStatus object representing the status of the command.

TableMapping Gets the DataTableMapping sent with the Update command.

OleDbDataReader

The OleDbDataReader class represents a lightweight, streaming method for retrieving data from a data source. It is similar to a DataSet, but provides less functionality with increased performance. Table C.17 lists the properties and methods of this class.

Table C.17. Properties and Methods of the OleDbDataReader Class
Property Description
Depth The depth of the reader.
FieldCount The number of fields within the current record.
IsClosed Indicates if the data reader is closed.
Item The value at the specified column in its native format. This method is overloaded.
RecordsAffected The number of records affected by the command. Typically, this is one if successful, less than one otherwise.
Method Description
Close Closes the OleDbDataReader object.
GetBoolean Returns the value at the column specified as a Boolean value.
GetByte Returns the value at the column specified as a Byte value.
GetBytes Returns the value at the column specified as a Byte array.
GetChar Returns the value at the column specified as a Char value.
GetChars Returns the value at the column specified as a Char array.
GetDataTypeName Returns the data type of the column specified.
GetDateTime Returns the value at the column specified as a DateTime value.
GetDecimal Returns the value at the column specified as a Decimal value.
GetDouble Returns the value at the column specified as a Double value.
GetFieldType Gets the Type that is the data type of the object.
GetFloat Returns the value at the column specified as a Float value.
GetGuid Returns the value at the column specified as a globally unique identifier value.
GetInt16 Returns the value at the column specified as a 16-bit signed integer.
GetInt32 Returns the value at the column specified as a 32-bit signed integer.
GetInt64 Returns the value at the column specified as a 64-bit signed integer.
GetName Returns the name of the column specified.
GetOrdinal Gets the column's index, given the column name.
GetSchemaTable Returns a DataTable object that describes the column metadata for this object.
GetString Returns the value at the column specified as a String value.
GetTimeSpan Returns the value at the column specified as a TimeSpan value.
GetValue Returns the value at the column specified in its native format.
GetValues Returns all of the attributes for the current record, and places them in a specified array.
IsDBNull Used to indicate nonexistent values.
NextResult Advances the reader to the next result, when reading from the results of batch SQL statements.
Read Moves the reader to the next record.

OleDbError and OleDbErrorCollection

The OleDbError class collects information about a warning supplied from the data source. Table C.18 lists the properties of this class.

Table C.18. Properties of the OleDbError Class
Property Description
Message A short description of the error.
NativeError The database-specific error information.
Source Gets the object that generated the error.
SQLState Retrieves the five-character standard error code for the database.

Table C.19 lists the properties and method of the OleDbErrorCollection class, which represents a collection of OleDbError objects.

Table C.19. Properties and Method of the OleDbErrorCollection OClass
Property Description
Count The number of errors in the collection.
Item Gets an OleDbError in the collection with the specified index.
Method Description
CopyTo Copies the entire collection to an array, starting at the specified index.

OleDbParameter and OleDbParameterCollection

The OleDbParameter class represents a value that is passed along with a database command to provide additional information or options. Table C.20 lists the properties and method of this class.

Table C.20. Properties and Method of the OleDbParameter Class
Property Description
DbType The data type of the data source.
Direction Indicates how the parameter will be used. Can be: Input, InputOutput, Output, or ReturnValue.
IsNullable Indicates if the parameter is allowed to contain a null value.
OleDbType Specifies the Type of this parameter. (This property does not exist in the corresponding SqlParameter class.)
Offset The offset to the Value property. (This property only exists in the SqlParameter class.)
ParameterName The name of the parameter.
Precision The maximum number of digits used to represent the parameter.
Scale The number of decimal places used to represent the parameter.
Size The maximum size of this parameter.
SourceColumn The name of the column in the data source mapped to the DataSet used for returning Value.
SourceVersion Specifies the row version to use when loading data.
Value The value of the parameter.
Method Description
ToString Returns the ParameterName.

Table C.21 lists the properties and methods of the OleDbParameterCollection class, which represents a collection of OleDbParameter objects.

Table C.21. Properties and Methods of the OleDbParameterCollection Class
Property Description
Count The number of OleDbParameter objects in the collection.
Item Gets an OleDbParameter in the collection with either the name of the parameter or its index in the collection.
Method Description
Add Adds a parameter to the collection. This method is overloaded.
Clear Clears the collection of all OleDbParameter objects.
Contains Indicates if the OleDbParameter with the specified name exists in the collection.
CopyTo Copies the entire collection to a specified array, starting at the specified index.
IndexOf Retrieves the index of the specified parameter. This method is overloaded.
Insert Inserts an OleDbParameter object at the specified index.
Remove Removes the specified parameter from the collection. This method is overloaded.
RemoveAt Removes the OleDbParameter at the specified index.

OleDbTransaction

The OleDbTransaction class represents a transaction that occurs at the data source. Table C.22 lists the properties and methods of this class.

Table C.22. Properties and Methods of the OleDbTransaction Class
Property Description
Connection The OleDbConnection object associated with this transaction.
IsoloationLevel The isolation level for this transaction. Can be Chaos, ReadCommitted (default), ReadUncommitted, RepeatableRead, Serializable, or Unspecified.
Methods Description
Begin Starts the transaction. Subsequent commands and changes will all be stored in a transaction log pending committal, and can be rolled back at any time.
Commit Commits all changes since calling Begin.
RollBack Rolls back all changes that have been made to the data source since the Begin or Commit methods were called.


    IOTA^_^    
    Top


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne

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