How to count number of record in dataset [Resolved]

Posted by perfectchourasia-9163 under ASP.NET on 12/8/2011 | Points: 10 | Views : 21144 | Status : [Member] | Replies : 4
How to count number of record in dataset

ds.Tables["Url"].Rows.Count; i have used this but it return 702 count that is incorrect i have 3 record.

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/



Responses

Posted by: Sksingh on: 12/8/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

ds.Tables["Url"].Rows.Count, will return total number of rows in your "Url" table.

As you know dataset could contains multiple tables.

so
if you want to know total numbers of tables in your dataset then it will be as below
int count = ds.Tables.Count;
it will return total count of tables in particular dataset .

suppose if you have 3 tables (t1,t2,t3) inside your dataset "ds" .
and u want to know abt total number of rows in any particular table then it should like below
int totalrows = ds.Tables["tableName"].Rows.count;

ie. int totalrows = ds.Tables["t1"].Rows.count;
for t1 table.

Regards,
Sunil

perfectchourasia-9163, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 12/8/2011 [Member] Silver | Points: 25

Up
0
Down
Does your dataset has multiple tables?
or can you attach your code for debuging.

Thanks,
Sanjay

perfectchourasia-9163, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 12/8/2011 [Member] Bronze | Points: 25

Up
0
Down
Not sure but do one thing give datatable name anything except "Url" and then try again

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

perfectchourasia-9163, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 12/8/2011 [Member] Silver | Points: 25

Up
0
Down

You can also use index of table instead of table name .
If your dataset has 2 tables. you can use following syntax to check the value.


Response.Write(ds.Tables[0].Rows.Count.ToString());
Response.Write(ds.Tables[1].Rows.Count.ToString());

Thanks,
Sanjay

perfectchourasia-9163, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response