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
}
Author by
im useless
Updated on June 04, 2022Comments
-
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 about 13 yearsWould it be the same effect if you check first if the SqlDataAdapter returns null value?
-
Hogan about 13 years@eibhrum - you can have an empty data adapter.
-
-
Hogan about 13 yearsSince when does a data adapter have a rows attribute?
-
BrokenGlass about 13 yearstypo - should have been
dt
- fixed -
BrokenGlass about 13 years
dt.Rows.Count
is a property not a method, so this won't compile -
im useless about 13 years@brokenglass, what would i do?
-
Hogan about 13 yearsyes I saw that just before your comment... seems between the two of us we might write a line that compiles. :D