Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.Net Datareader Basics

Status
Not open for further replies.

ViperPit

Programmer
Joined
Aug 4, 2005
Messages
30
Location
US
I have a couple basic questions about ADO.Net datareaders and how they relate to the older Recordsets from ADO.

1.) How do you test to see if the Dtareader contains any data?
In ADO, you would open a recordset and check for EOF.
I don't see anything similar with the Datareader.
To loop in ADO you would "Do While Not EOF" and then have a "MoveNext" at the bottom of the "Loop".
I looks like the Datareader has the same loop functionality with "While myReader.Read()" function. But how do you do an initial test for emptiness without looping?

2.) Can a DataReader see changes made in subsequent rows by other users?
In ADO, this was done by opening the recordset with the "ADODB.CursorTypeEnum.adOpenDynamic" option.
I can't find anything similar with the DataReader.
I read that it only retrieves one row at a time, but I didn't understand if that was just referring to stepping though the data on the client side, or whether that meant retrieving the data from the server.
If I open a query with a datareader and Read the first row, and then another user changes what will end up being my 5th row, when I get to Read that 5th row, will I see their changes?

Thanks. :)
 
1. DataReader.HasRows
2. I'm not sure. It shouldn't matter too much, because it reads in forward-only. Normally, you're going to be looping with .Read(), so it's going be similar to just running a query and gettings the results back. You could easily test this pausing in the loop and changing your db values, then taking off the pause.
 
1) The DataReader has a Boolean HasRows property. The datareader is however forward read only, and is the nearest thing comparable to old ADO.

2) For anything to do with concurrent changes you will need to look at datasets and dataadapters. You can use a data adapter to test for changes made by other users, by firing its update method. Each row of every datatable in your dataset has a row property to indicate its current row status (ie updated, deleted, added)

Sweep
...if it works dont f*** with it
curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top