通过查询了,下面是我写的一点代码,着段代码返回一个值,不知道楼主能否看的通 public int ExecuteSca(string sql) { SqlCommand cmd = new SqlCommand(sql, getConnection()); if (null ==cmd.ExecuteScalar()) //判断是否为空,如果为空就说明没找到了 {return 0;
} else { int a = (int)(cmd.ExecuteScalar());//如果不为空就说明里边有值了 if (a > 0) { return a; } else { return 0; }
public int ExecuteSca(string sql)
{
SqlCommand cmd = new SqlCommand(sql, getConnection());
if (null ==cmd.ExecuteScalar()) //判断是否为空,如果为空就说明没找到了
{return 0;
}
else
{
int a = (int)(cmd.ExecuteScalar());//如果不为空就说明里边有值了
if (a > 0)
{
return a;
}
else
{
return 0;
}
}
}