Game Development Reference
In-Depth Information
DataProvider
There are two group classifications for managed provider components: one to com-
municate with regular data sources and one that is optimized for communication
with SQL Server 2000 and higher. All of these providers comply with the standards
defined in the System.Data.Common namespace.
The first component is the connection object. Just like ADO, this object manages
the connection string and connection state. This object still has the usual Open()
and Close() methods. There is now a BeginTransaction() method that is used to
control a database transaction. The regular group has the OleDbConnection , while
the optimized SQL Server provider is SqlConnection .
The next component is the command object. This object serves as the transfer pipe
for the data. You can execute queries that do not return any rows (using the
ExecuteNonQuery() method), execute a query that returns a single value like an ID
(using the ExecuteScalar() method), or execute a query that returns a data reader
(using the ExecuteReader() method). The regular group has the OleDbCommand , while
the optimized SQL Server provider is SqlCommand .
Another component is the data reader object. This object associates itself with a
data stream from the command object and provides a mechanism to perform for-
ward-only reading. This method is very efficient, but intensive queries should be
avoided since this uses a server-side cursor, tying up a connection resource until it
finishes. The regular group has the OleDbDataReader , while the optimized SQL
Server provider is SqlDataReader .
The last component is the data adapter. This object consolidates many of the other
components into this easy-to-use class. A data adapter basically uses your connec-
tion to retrieve results, and then passes the data to a DataSet , which can then be
updated or displayed. If rows are changed, the DataSet can be passed back into the
data adapter to be persisted into the database. You can set the SQL statements
using the InsertCommand , UpdateCommand , SelectCommand , and DeleteCommand proper-
ties. The regular group has the OleDbDataAdapter , while the optimized SQL Server
provider is SqlDataAdapter .
Working with a DataReader
The following example shows how to select rows from an Access database file and
display a message box for all the rows in SomeTextColumn .
Search Nedrilad ::




Custom Search