Dates Acces versus SQL

Problem with dates in Select statement

Page 1 of 1

4 Replies - 921 Views - Last Post: 09 November 2009 - 11:40 PM Rate Topic: -----

#1 ABO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

Dates Acces versus SQL

Post icon  Posted 08 November 2009 - 10:46 AM

Hello,

I have a Acces database and vbnet2008.

When i run the qwery below i've got the error message " Data Type Mismatch in Criteria Expression"


strSQL = "Select * FROM Cars WHERE " & strChoice & "=" & "'Yes' AND DateMake BETWEEN '" & dtpBegin.Value & "' AND '" & dtpEnd.Value & "'"

Where DateMake is a date in the Acces dbase and save as date
dtpBegin and dtpEnd are dates from a datetimepicker in the program
When i'm looking at the dates in Watch there no different between the "looking"of the dates

Whats wrong?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Dates Acces versus SQL

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Dates Acces versus SQL

Posted 08 November 2009 - 10:51 AM

Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,201
  • Joined: 25-September 09

Re: Dates Acces versus SQL

Posted 08 November 2009 - 01:11 PM

Try enclosing the dates in # instead of '

so WHERE Date between #01/01/2009# and #01/31/2009#
Was This Post Helpful? 0
  • +
  • -

#4 ABO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-April 09

Re: Dates Acces versus SQL

Posted 09 November 2009 - 08:48 AM

View PostCharlieMay, on 8 Nov, 2009 - 12:11 PM, said:

Try enclosing the dates in # instead of '

so WHERE Date between #01/01/2009# and #01/31/2009#


thats works perfect, but i'm working with datetimepickers so i want use them values
still, why did it work with your solution and not with de datetimepickers values???
Was This Post Helpful? 0
  • +
  • -

#5 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Dates Acces versus SQL

Posted 09 November 2009 - 11:40 PM

Hi,

I access, date value have to be enclosed with the hashes in sql statements like this #01-01-2000#. In MSSQL its done with single quotes. like this '01-01-2000'.

Just mind the format of your date. I prefer sending it like this #01-Jan-2000# (Access) or '01-Jan-2000' (MSSQL).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1