techBeginner
techBeginner

Reputation: 3850

SqlCeDatareader.HasRows raising exception

enter image description here

How to solve the issue?

OR is there any other way to check if the result contains any records?(except rdr.Read() method)

btw I am using Sqlserver Compact 3.5

Upvotes: 0

Views: 691

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

You say "except rdr.Read() method" but that feels like the most natural approach to me.

Call Read(), and if it returns true, populate the result, otherwise set the result to null.

Also note that

catch (Exception e)
{
    throw;
}

is generally an abomination which should be removed. I would also question a design and implementation which:

  • Ignored naming conventions (getSites)
  • Used a bool return value but always returned true, and an out parameter for the real results
  • Didn't dispose of the command itself
  • Declared the rdr method way before it's needed, for no obvious reason. (It's not going to be useful outside the using statement anyway, so why not declare it there?)

Upvotes: 1

Related Questions