Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

NEWBIE: How to test if OleDbDataReader is empty without reading it?

Dear Experts,

I have a method that accepts an OleDbDataReader, solely to determine if it's empty.  This was a problem with Java ResultSets, which I'm converting to C#.  You had to use a special "isAfterLast" method if you wanted to determine emptiness without actually reading from the ResultSet.  I see something called "hasRows()", but it doesn't seem to be an actual method of OleDbDataReader.  (I'm a TOTAL C# newbie...)

Thanks!
--BrianMc1958
0
BrianMc1958
Asked:
BrianMc1958
  • 2
1 Solution
 
topdog770Commented:
OleDbDataReader has a boolean property called HasRows
0
 
wlfsCommented:
You are on the right track. HasRows does exactly what you want. It returns a boolean value indicating whether the DataReader is empty (HasRows is false) or not (HasRows is true).

hasRows() - as you wrote - won't work for two reasons: First, C# is case sensitive, you have to capitalize the "H" of HasRows. Second, HasRows is a property not a method. If you don't implement properties but just use them, you can think of them as normal object variables. So, you must not use parenthesis, just "HasRows":

if (myDataReader.HasRows) {
  // do something
}
0
 
BrianMc1958Author Commented:
Excellent!  I love making the dumb mistakes you learn from!  I was just automatically putting in the "()" after HasRows...

Thanks again!
--BrianMc1958
0
 
topdog770Commented:
lol, thanks wlfs, that will teach me to type in text before drinking my morning coffee!!

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now