Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid  
Author Message
tony19760619





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

1. I have a webforms application.
2. I am checking the number of rows is higher than 0
if (DataSet1.Tables(0).Rows.Count() > 0)

3. The value is always 0 even though I have retrieved rows from this DataTable into my DataGrid.

Any Ideas
Please help..


.NET Development29  
 
 
Jens K. Suessmeyer





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

Perhaps you are using another table than this with the index 0 See what DataSet1.Tables.Count bring back...

HTH, Jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---


 
 
tony19760619





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

The DataSet1.Tables.Count brings back 1.

I am using SQL server 2000 on DotNet 2003.

Is there some sort of compatibility issues


 
 
Jens K. Suessmeyer





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

this is really strange, the count bringing back 0 and the databinding which is able to bind rows


HTH, Jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---

 
 
Peter Gvozdjak - MSFT





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

Moving to the .NET Framework Data Access and Storage forum, which may provide more suggestions given that this is managed code.



 
 
tony19760619





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

This occurs in Web-Forms Applications.

I thought you only have to fill in the DataSet once.
And then be able to use the data contained in it on any future call.
But the data is reset when a Post Back occurs.

So I am filling up the dataset again in the Page_Load().
Making sure it is not within a "If Not (Page.IsPostBack)" statement.

If anybody knows of a better method(where I would only call the DB once) please let me know.

 
 
Bappi





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

u have said that its a web form. So I guess you are checking from some where else.

Can you please provide the code that u are using.

Thanks



 
 
Dinesh Singh Bisht





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

One of the way we use this in our application is:

while fetching data in (!IsPostBack) store the same data in a cache object and use the cached values later on.

This will reduce all database calls to one call [at the time of first time page load].

Let me know if I can help you anymore in this



 
 
Kzin





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

I may have the answer, but I may be wrong.
To me I see two places. One, should you use square brackets for the index search Also, it seems like you are using a property as a function and should remove the round brackets after Count.

Ex; if(DataSet1.Tables[0].Rows.Count > 0)

 
 
tony19760619





PostPosted: .NET Framework Data Access and Storage, Why Tables.Rows.Count is 0 even though rows are displayed in DataGrid Top

I used the DataGrid component the cache the data.
Am it worked just fine.