Counting rows with a SqlDataAdapter

13,594

Solution 1

Maybe try dt.Rows.Count since that is a table and has rows.

Solution 2

You were doing an assignment instead of a comparison, you have to use == :

if (dt.Rows.Count == 0 )
{
    // code here
}
Share:
13,594
im useless
Author by

im useless

Updated on June 04, 2022

Comments

  • im useless
    im useless about 2 years

    I have a problem in my code. I want to get the row count from my SqlDataAdapter if there are any rows.

    • abramlimpin
      abramlimpin about 13 years
      Would it be the same effect if you check first if the SqlDataAdapter returns null value?
    • Hogan
      Hogan about 13 years
      @eibhrum - you can have an empty data adapter.
  • Hogan
    Hogan about 13 years
    Since when does a data adapter have a rows attribute?
  • BrokenGlass
    BrokenGlass about 13 years
    typo - should have been dt - fixed
  • BrokenGlass
    BrokenGlass about 13 years
    dt.Rows.Count is a property not a method, so this won't compile
  • im useless
    im useless about 13 years
    @brokenglass, what would i do?
  • Hogan
    Hogan about 13 years
    yes I saw that just before your comment... seems between the two of us we might write a line that compiles. :D