SqlCommand sd1 = new SqlCommand("select sum(pric) from cart where uid='" +
Convert.ToInt32( Session["uid"]) + "'",con);
// sd1.ExecuteNonQuery();
int var1 = Convert.ToInt32( sd1.ExecuteScalar());
答案 0 :(得分:0)
DBNull.Value
。您需要在演员表中考虑到这一点。以下内容将转换为可为空的int
,以便在没有找到记录的情况下进行表示。代码:
int? intResult;
using(SqlCommand sd1 = new SqlCommand("select sum(pric) from cart where uid=@uid", con))
{
sd1.Parameters.Add(new SqlParameter("@uid", SqlDbType.Int){Value = Convert.ToInt32(Session["uid"])});
var result = sd1.ExecuteScalar();
intResult = Syste.DBNull.Value == result
? (int?) null
: (int?) result;
}