You will always need a SqlConnection and SqlCommand.
The SqlConnection establishes the network connection to the database.
The SqlCommand contains information about what the database should process.
The question that remains is "Should I remain connected when processing the query?". This then splits your query into 2 camps:
1) Connected.
2) Disconnected.
The "Connected" classes mean that the connection is maintained, and you would programatically retrieve columns. This is known to be faster, although slightly more code is required. You also have to open and close connections yourself.
These are in the form of DataReader's.
The "Disconnected" classes open the connection, download the whole result of the query to a DataSet and disconnects by itself.. no need to open and close the connections yourself.
These are in the form of DataAdapter's.
I picture the DataSet as a database in memory. A dataset can have tables (DataTable) and each table consists of rows (DataRows) and columns (DataColumns). You can also define relationships between tables (DataRelations), should you wish to cross reference data.
.NET 2.0 helps ease the process by generating DataSets specific to your query. So for example, say you write a stored procedure to get all of the customers in a database, you can tell .NET (in design time) to create a DataSet which matches the data returned from this stored procedure, which is type-safe and named with the column names from your database.
There are plenty of resources on the net discussing the differences between connected and disconnected ADO .NET. Once you start using these classes, you'll wonder how you ever got them confused :-)
Hope this helps,
Dominic
|