Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1111041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:29:09+00:00 2026-05-17T02:29:09+00:00

Environment Mono, PostgreSQL, .Net MVC, Windows I’m try to show all events that occur

  • 0

Environment
Mono, PostgreSQL, .Net MVC, Windows

I’m try to show all events that occur in the future.

In order to do that I’m using the following SQL:

NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM dinners WHERE EventDate >= " + DateTime.Now, dinnerConn);

Now, if I compare DateTime.Now and my EventDate timestamp from the DB, I get the following

(EventDate) 12/18/2010 7:00:00 PM - (DateTime.Now) 10/2/2010 7:59:48 PM

They seem pretty easily comparable to me, but whenever I run this query, I get the following:

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 

Now, I know the application works otherwise because if I ask it to pull all dinners, or all dinners greater than a specific ID, or a specific dinner, everything works fine, it just seems to be trying to compare timestamp to DateTime.Now.

I know this is something simple. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:29:10+00:00Added an answer on May 17, 2026 at 2:29 am

    This syntax should fix your problem:

    NpgsqlCommand sql = db.CreateCommand();
    sql.CommandType = CommandType.Text;
    sql.CommandText = @"SELECT * FROM dinners WHERE EventDate >= @eventdate ;";
    sql.Parameters.Add("eventdate", NpgsqlType.Date).Values = DateTime.Now;
    

    You consider to change your query (reference) so both timestamps are almost the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: Windows Server 2003 R2 Enterprise 64bit, SP2 .NET framework is supposedly installed (2.0
Environment: Windows 2003 Server (32 bit); IIS6, ASP.NET 2.0 (3.5); 4Gb Ram; 1 Worker
I'm using Emacs and Mono on Windows so that I can retain the same
Environment I'm working on a C++ application that uses SQL Native Client 9.0 to
Environment is VS2008, .Net 3.5 The following C# code (note the specified encoding of
Environment: C# projects, Visual studio 2008, C#, .Net 3.5, MSBuild Objective: Run my own
Environment: Rails 2.2.2, Oracle 10g Most of the columns declared date in my ActiveRecord
Environment: Team Foundation Server 2005 Visual Studio 2008 I have a reasonably large project
My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio
Does your work environment use Harvest SCM? I've used this now at two different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.