-1

我试图计算一列中所有数字的总和。

列名是整数类型的“单位”。

这应该有效吗?

cmd3 = New OleDbCommand("SELECT SUM(Units) FROM tblJobs WHERE BookedOut = NULL AND HoldDate = NULL ", con)

lblLiveUnits.Text = cmd3.ExecuteNonQuery()

谢谢

4

1 回答 1

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()
于 2013-04-16T10:24:17.053 回答