我有以下函数来检查我的 SQL 表中是否存在用户
private static bool userexists(string user)
{
bool userexists = false;
SqlCommand c = new SqlCommand("SELECT COUNT(*) from UserTable where Username = @user");
c.Parameters.Add(new SqlParameter("@user",user));
using (SqlConnection con = new SqlConnection(Properties.Settings.Default.connectionString))
{
userexists = (bool)c.ExecuteScalar();
return userexists;
}
}
即使用户存在它也会返回false
,我做错了什么?