我试图计算一列中所有数字的总和。
列名是“单位”类型的整数。
这应该有用吗?
cmd3 = New OleDbCommand("SELECT SUM(Units) FROM tblJobs WHERE BookedOut = NULL AND HoldDate = NULL ", con)
lblLiveUnits.Text = cmd3.ExecuteNonQuery()
谢谢
答案 0 :(得分:3)
您的查询不正确,您不想制作=NULL
您应该使用IS NULL
的内容:
SELECT SUM(Units) As TotalUnits
FROM tblJobs
WHERE BookedOut IS NULL
AND HoldDate IS NULL
然后在您的代码中,您将使用ExecuteScalar
:
Int32 lblLiveUnits = 0;
cmd3 = New OleDbCommand("SELECT SUM(Units) As TotalUnits FROM tblJobs WHERE BookedOut IS NULL AND HoldDate IS NULL ", con);
lblLiveUnits = cmd3.ExecuteScalar()