Joined: Fri Oct 19, 2007 9:46 am Posts: 5
|
|
As previously discussed I briefly outlined the advantages and disadvantages of using Data Sets within your website applications. In this discussion post I will outline the benefits and drawbacks of using the SqlCommand and SqlReader classes.
The SqlCommand and SqlReader classes are required when manipulating data in a connected state. This means when a connection to the database is actually open.
SqlCommand Class
The SqlCommand class should be used when retrieving and updating data on the database. This class uses SQL to provide the functionality on the database. You could create a SELECT statement in SQL which the SqlCommand class will execute. You could then feed the SqlCommand class to a Data Reader which will actually retrieve all of the data you require from the database.
SqlReader Class
The SqlReader class is used to iterate through the records returned from your SqlCommand just executed. It provides sequential access to each individual record and it can only move to the next record, rather than moving both forwards and backwards.
When to use the SqlCommand and SqlReader classes?
You should use these two classes simultaneously when you want to access data that is frequently upated or when up-to-date data is critical to your application.
|
|