【发布时间】:2011-07-12 07:52:48
【问题描述】:
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;
}
问题是对象总是接收到一个非空值。但是在“禁止”字段的“用户”表中,我将其类型设置为“允许空值”......我可以看到有空值,但没有检索到空值......其他的东西......这使得“isBanned”参数成为真的..一直..为什么会发生,我怎么知道对象什么时候是布尔真。
【问题讨论】: