If no user is found, then a count of 0
will be returned. Since you convert this int
result into the string "0"
its length will be 1
. "0".Length == 1
!
Since an int
result is returned by ExecuteScalar()
(statically typed as object
), cast it to an int
instead of converting it to a string
:
int result = (int)command.ExecuteScalar();
if (result > 0) {
...
} else {
...
}
Also, as Volodymyr Melnychuk has already pointed out, the parameter in the SQL string should be
called @username
instead of @uername
.
You are missing a space between dbo.ClientLogin
and WHERE
.
Replace
string queryText = "... dbo.ClientLogin" +
"WHERE ...";
by
// see the space here v
string queryText = "... dbo.ClientLogin " +
"WHERE ...";
Other possible reasons: The table name is incorrect, the table is not in the dbo
schema, a column name is incorrect, you don't have the required access rights.