I spent hours trying to figure out why the code wasnt' returning the correct value.
No matter what I do I was only getting -1.
Finally, after few research and all that I found out that SELECT and cmd.ExecuteNonQuery() is no t the way to go.
but instead a simple solution would be to use ExecuteScalar().
But the catch with using ExecuteScalar is to use Select Count(*) from ... instead of Select * from ...
Hence, finally was able to do this by using
Select Count(*) form ...
and then
int i = (int)cmd.ExecuteScalar();
No comments:
Post a Comment