getting number of rows - dataadapter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a datagrid populated from a dataadapter that is databound when the user picks a choice from a dropdownlist
Depending on the choice, the user queries the database and may get considerable amount of rows returned. But then again, no rows may be returned at all - because of the parameter the user has chosen
I want to check the number of rows in the dataadapter before I bind it to the datagrid. If the query returns no rows, no datagrid is displayed. Now I am having an empty datagrid displayed in this case, I do not want it to show at all
I know about the HasRows property, but it only seems to apply to the datareader. As I want to page the datagrid (the number of rows may be up to 300 returned), I think I cannot use it, can I

Is there any way of doing this, without changing my code
Any help would be much appreciated

Kaspian
 
if( DataTables.Rows.Count > 0){//BindGrid}

If you are requerying the database each time though, that's unnecessary
overhead in most instanes. You may want to pull over both tables, use a
datarelation and when the selectedIndex changes in the listbox, let the
bindingcontext change the values for you.... That's another issue though.
If your sole need right now is to know if you have rows, the above code will
work for you.

You could also think of binding your grid to a dataview and setting the
rowfilter based on the value in the listbox.. I have an example here.
http://www.knowdotnet.com/articles/dataviews1.html

It will take a lot of stress off of your db and probably speeed things up
notably.

Cheers,

Bill
Kaspian said:
Hi!

I have a datagrid populated from a dataadapter that is databound when the
user picks a choice from a dropdownlist.
Depending on the choice, the user queries the database and may get
considerable amount of rows returned. But then again, no rows may be
returned at all - because of the parameter the user has chosen.
I want to check the number of rows in the dataadapter before I bind it to
the datagrid. If the query returns no rows, no datagrid is displayed. Now I
am having an empty datagrid displayed in this case, I do not want it to show
at all.
I know about the HasRows property, but it only seems to apply to the
datareader. As I want to page the datagrid (the number of rows may be up to
300 returned), I think I cannot use it, can I?
 
Thanks

This approach should do great, thank you! You helped me a lot

cheers to You too

Kaspian
 
Back
Top