I want to check if my query returns any value or not and write the remaining logic accordingly.
SqlCommand myCommand = new SqlCommand("Select * from phc.userbase where [user]='@Username' and [password]='@password'", myConnection);
I want to know this command returns null or not. I tried
myReader = myCommand.ExecuteReader();
bool rd = myReader.Read();
if rd==false
but I can’t get it working. Any ideas?
Here are my parameters:
SqlParameter myParam = new SqlParameter("@Username", SqlDbType.VarChar, 25);
myParam.Value = usr;
SqlParameter myParam2 = new SqlParameter("@password", SqlDbType.VarChar, 25);
myParam2.Value = pass;
It depends what you mean by
nullhere; do you mean “no rows” ? If so:To be honest, though, you could probably change that to
SELECT 1 ...and useExecuteScalar– much less bother.In this case, though, it is probably easier to just
SELECT 1 ...rest of query...and use: