一些幫助,將不勝感激。如果今天等於或少於從表中獲取expiredate SQL Server CE
我有一個表tblItem
的列ExpireDate
(DateTime
),AlertDays
(Int
)。我想在expiredate
之前x天提醒您。
我想統計today + alertdays <= ExpireDate
的所有項目。
我有以下的代碼,但它造成的錯誤:
There was an error parsing the query. [ Token line number = 1,Token line offset = 48,Token in error = select ]
請看看我的代碼:
internal static int getAlertDateExpire()
{
SqlCeConnection con = ConectionAndData.Con;
if (con.State == System.Data.ConnectionState.Closed)
con.Open();
int number = 0;
string sqlCommand = "select count(*) from tblItem where (Getdate()+(select AlertDays from tblItem)) As today <= ExpireDate Order By ItemName ASC";
SqlCeCommand com = new SqlCeCommand(sqlCommand, con);
try
{
number = (Int32)com.ExecuteScalar();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
return number;
}
Ashkan Mobayen:我試了你的建議,並得到這個錯誤消息:解析查詢時出現錯誤。 [令牌行號= 1,令牌行偏移= 50,令牌出錯=選擇] –
@PlazzaSele我更新了代碼。並通過獲得計數的方式,你不需要'訂單的條款 –
Ashkan:感謝您的幫助,但仍造成錯誤:SqlCeException被捕獲:解析查詢時出錯。 [令牌行號= 1,令牌行偏移= 50,令牌出錯=選擇] –