public static bool CheckIfUserISbanned(Guid guid)
{
StringBuilder sb = new StringBuilder();
sb.Append("SELECT Banned");
sb.Append(" FROM dbo.Users");
sb.Append(" WHERE UsersID=@UserID");
object o;
bool isBanned = false;
string myConnectionString = AllQuestionsPresented.connectionString;
using (SqlConnection conn = new SqlConnection(AllQuestionsPresented.connectionString))
{
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
conn.Open();
cmd.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = guid;
o = cmd.ExecuteScalar();
}
isBanned = o == null ? false : true;//Problem here
return isBanned;
}
Run Code Online (Sandbox Code Playgroud)
问题是该对象始终接收一个非null值.但是在Banned字段的Users表中,我将其类型设置为"Allow Nulls"...我可以看到有空值,但是没有null被重新读取.还有其他的...这使得"isBanned"参数成为真的...整个时间..为什么会发生,我怎么知道对象是什么时候是bool True.