尝试从Firebird数据库中选择数据时遇到问题,这是我的代码:
string SQLCash = "SELECT sum(t2.Cash-Change)" +
"FROM dbFBHdr t1, dbFBCollection t2" +
"WHERE t1.Branch = t2.Branch AND" +
"t1.CashNo = t2.CashNo AND" +
"t1.CashDate >= '08/10/2018 00:00:00' AND" +
"t1.CashDate <= '08/10/2018 23:59:59' AND" +
"t1.Status = 'CLOSED'";
FbCommand cmdCASH = new FbCommand(SQLCash, FbCon);
cmdCASH.ExecuteNonQuery();
FbDataReader readerCASH = cmdCASH.ExecuteReader();
while (readerCASH.Read() == true)
{
PDC.CASH += (reader["Cash"].ToString());
}
this.txtCash.Text = PDC.CASH;
但是使用此代码,我遇到了一个错误,但是我不知道如何解决。
我将错误附在下面:
答案 0 :(得分:1)
我在您的项目中运行了您的代码 这就是结果
"SELECT sum(t2.Cash-Change)FROM dbFBHdr t1, dbFBCollection t2WHERE t1.Branch = t2.Branch ANDt1.CashNo = t2.CashNo ANDt1.CashDate >= '08/10/2018 00:00:00' ANDt1.CashDate <= '08/10/2018 23:59:59' ANDt1.Status = 'CLOSED'"
您可以看到上面的代码在添加字符串之间缺少空格,可以在每个字符串的开头或结尾添加它。
另外,由于您正在使用多行,因此可以在字符串之前使用@
,这将使您可以在一个字符串中包含多行,例如
string SQLCash = @"SELECT sum(t2.Cash-Change)
FROM dbFBHdr t1, dbFBCollection t2
WHERE t1.Branch = t2.Branch AND
t1.CashNo = t2.CashNo AND
t1.CashDate >= '08/10/2018 00:00:00' AND
t1.CashDate <= '08/10/2018 23:59:59' AND
t1.Status = 'CLOSED'";