public Boolean ExecSqlSelect(string sQueryString)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlCommand dbCommand = new SqlCommand(sQueryString, con);
if (dbCommand.ExecuteScalar().ToString!= null)
{
con.Close();
return true;
}
else
{
con.Close();
return false;
}
}
老是说为将对象的引用设置到对象的实例!!
这句话不出错,真奇怪??Tostring()..
如果单纯判断NULL,去年tostring()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlCommand dbCommand = new SqlCommand(sQueryString, con);
return dbCommand.ExecuteScalar() != null
}
等于null 不需要转换的
你只要稍微短点调试一下就清楚了。
原因就是你的dbCommand.ExecuteScalar()直接判断是否空就可以了
但是你的问题是:如果dbCommand.ExecuteScalar()为空,再.ToString()的话
问题就出来啦。
谢谢大侠!!
if (dbCommand.ExecuteScalar().ToString!= null)