0

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

techBeginner
  • 3,792
  • 11
  • 43
  • 59

1 Answers1

1

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?)
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • If you dont call Read, you wont even get the first row's data, so I am not sure what the OP is after :S – leppie Oct 25 '11 at 11:06
  • actually .Read moves the record one step further, so I am going to miss first record.. and thank you for design related suggestions.. :) – techBeginner Oct 25 '11 at 11:11
  • 1
    @dotNETbeginner: So just call the extension method unconditionally, and you'll get no results back if there were no rows. – Jon Skeet Oct 25 '11 at 11:24
  • @dotNETbeginner: It is at `-1` initially. – leppie Oct 25 '11 at 11:47