环境 单声道和PostgreSQL,净MVC中,Windows净DateTime.Now VS PostgreSQL的时间戳比较
我试图证明在未来发生的所有事件。
为了做到这一点,我使用的SQL语句:
NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM dinners WHERE EventDate >= " + DateTime.Now, dinnerConn);
现在,如果我比较DateTime.Now和我EVENTDATE时间戳从数据库中,我得到以下
(EventDate) 12/18/2010 7:00:00 PM - (DateTime.Now) 10/2/2010 7:59:48 PM
他们似乎很容易比较给我,但每当我运行此查询,我得到如下:
ERROR: 42601: syntax error at or near "8"
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Npgsql.NpgsqlException: ERROR: 42601: syntax error at or near "8"
Source Error:
Line 106: try
Line 107: {
Line 108: NpgsqlDataReader reader = command.ExecuteReader();
Line 109: while (reader.Read())
Line 110: {
Source File: c:\Documents and Settings\Andrew\My Documents\Visual Studio 2008\Projects\MvcApplication1\MvcApplication1\Models\DBConnect.cs Line: 108
现在,我知道该应用程序的其他功能,因为如果我要求它将所有晚餐或所有晚餐都大于特定ID或特定晚餐,那么一切正常,它似乎只是将时间戳与DateTime.Now进行比较。
我知道这很简单。我究竟做错了什么?
sql参数的字符串concatenation是邪恶的。不要这样做。 – 2010-10-03 00:37:08