NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

The DataReader

When a large amount of data is being retrieved, the issue of holding memory open becomes a factor. For example, reading 10000 rows out of a database causes a DataTable to allocate and maintain memory for those 10000 rows for the lifetime of the table. If 1000 users do this against the same machine at the same time, memory usage becomes critical.

Also, if you are unsure of the results of a given query, and you need code to iterate over the stream, a DataTable is not ideal, as again, the entire steam would be loaded.

To resolve this, the DataReader is a read-only, forward-only steam returned from the database. Only one record at a time is ever in memory.

The DataReader is a forward-only, read-only accessor on top of a stream returned from the data store. You walk through the returned datareader in a very simple format:

[VB]

While myReader.Read
   ' Do something with the current row
End While 

[C#]

While (myReader.Read())
{
   //do something with the current row
}

The DataReader also provides a series of Get methods that allow accessing the field values as its native time. Examples of this are: GetDataTime, GetDouble, GetGuid, GetInt32, GetStream.