John
John

Reputation: 747

DataReader fundamentals

I have some questions from my Test and I want to be sure in my answers. Need to say sentence is true or false. So:

  1. The DataReader provides a cursor that can be used to move forward and backwards through the result.

False, because cursor can be used to move only to forward, not backwards.

  1. The DataReader provides random access capabilities on the result.

False, DataReader is cursor and don't allow to random access

  1. The Application code can reference the first row of a multi-row result set faster than it can be by loading it directly into a DataTable

I think, it's True, but not sure about multi-row.

  1. The DataReader can provide the Schema of the result to the application code.

I think, it's False, but never found it in documentation (that DataReader does not provide the Schema)

am I right in my answers?

Upvotes: 0

Views: 199

Answers (2)

Yoh Deadfall
Yoh Deadfall

Reputation: 2781

  1. Yes. it's forward only.
  2. You are right again.
  3. Because the DataReader is unbuffered and works with streams it's faster than loading a data into a DataTable.
  4. The DataReader can provide the Schema via DataReader.GetSchemaTable().

Upvotes: 1

SlavM
SlavM

Reputation: 26

In point 3. - DataReader will read one row at the time so it is faster (to fill table you must get all rows, convert them to objects and attach them to datasource). This is also a problem because (depends on sql configuration) will remain open until you read it all - this may cause some locking issues.

  1. There is way to get schema from DataReader http://support.microsoft.com/kb/310108/

Upvotes: 1

Related Questions