Search code examples
datasetreport-viewer2010

Checking if a dataset has any rows


In my current reportviewer i have a dataset that returns rows of information from stored procedure. I wanted to add a parameter in my report to display in the header area of the report the count of rows in the report. If there is no information to return to the reportviewer obviously the rows count will be 0. Is there a way in which i could try to count how many rows there are in the dataset/table and return that number in the header area in a textbox without linking it to any dataset?


Solution

  • You can take the count of rows in one form(say Form1)...save it in one integer variable...

    eg. public static int cnt=ds.Tables[0].Rows.Count;

    pass this integer value to dataset as a parameter (Form1.cnt)...

    Remember in this case declaration of variable as public static is important...

    After this you can insert the value into that table and take it on the report text box...

    OR

    You can simple count Fields in dataset by giving direct formula to that text box