public int RunProcGetCount(string procName,SqlParameter[] param)
{
string count;
SqlCommand cmd = createCommand(procName, param);
count=cmd.ExecuteScalar().ToString().Trim();
if (count == "")
{
count = "0";
}
Close();
return count;
}
出现如下错误:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 320: string count;
行 321: SqlCommand cmd = createCommand(procName, param);
行 322: count=cmd.ExecuteScalar().ToString().Trim();
行 323: if (count == "")
行 324: {
{
string count;
SqlCommand cmd = createCommand(procName, param);
count=cmd.ExecuteScalar().ToString().Trim();
if (count == "")
{
count = "0";
}
Close();
return count;
}
出现如下错误:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 320: string count;
行 321: SqlCommand cmd = createCommand(procName, param);
行 322: count=cmd.ExecuteScalar().ToString().Trim();
行 323: if (count == "")
行 324: {
{
SqlCommand cmd = createCommand(procName, param);
object count = cmd.ExecuteScalar();
if (count == null) count = 0;
Close();
return count.ToString();
}
如果没有查找到任何记录,就会出现这种错误
检查他。
看看你传递的参数进去了没有。
如果没有就会出现那种情况。
再有就是SQL语句出了问题。
检查检查为什么为空吧~!