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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataSet.Tables.Count giving different results on different m/c

Status
Not open for further replies.

asrir

Programmer
Sep 21, 2007
1
US
If there are no records returned by the sql what should be the value of myDataSet.Tables.Count. Is it 0 or 1 (with rows count 0)?

The same application returns 0 on one machine and 1 on another. We are executing the same query and pointing to the same database.

Can someone tell me why this would happen?

Thanks,
AS
 
If there is one table returned then the table count should be 1. Even if there are no records in the table it will(should) still have a table with the fields in it, just no rows?

Age is a consequence of experience
 
i was under the impression that you could never assume that collections returned would have anything in them at all. using adapter.fill is particularly cumbersome because you've got two nested collections, Tables and Rows. is there a quicker way of doing the checking than this?

Code:
dataAdapter.Fill(theSet, ...);
if ( theSet.Tables != null && theSet.Tables.Contains("TABLENAME") )
{
 if ( theSet.Tables["TABLENAME"] != null 
   && theSet.Tables["TABLENAME"].Rows != null 
   && theSet.Tables["TABLENAME"].Rows.Count > 0 )
 {
  foreach ( DataRow row in theSet.Tables["TABLENAME"].Rows )
  {
   // do something... 
  }
 }
}


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top