سؤال

I have a routine to pull data from my database (nothing fancy). I want it to pull rows in which the "StartDate" column is some date in the future. The code below pulls all the rows instead of just the future ones.

I know it must be something silly that I'm doing but I can't figure it out.

Thanks in advance,
Craig

CODE:

Printda = New OleDbDataAdapter("SELECT * FROM tblShows WHERE StartDate > " & Format(Now, "Short Date"), cn)

Updated Code:

Printda = New OleDbDataAdapter("SELECT * FROM tblShows WHERE StartDate > '" & Now.ToString("Short Date") & "'", cn)

Corrected Code:

Printda = New OleDbDataAdapter("SELECT * FROM tblShows WHERE StartDate > Now()", cn)
هل كانت مفيدة؟

المحلول

Try this:

"SELECT * FROM tblShows WHERE StartDate > #" & Now.ToString("MM/dd/yyyy") & "#"

In SQL Server this is the default date format. In Oracle is YYYY-MM-DD. Use the format that fit your needs, or use parameters if you don't want to care about formatting and give your querys security.

Or you could simply use proper function to get the actual date:

"SELECT * FROM tblShows WHERE StartDate > now()"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top