473,831 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error when comparing a date in an access database

I'm trying to get a bunch of records based on client id and a date range. I
keep getting an error when I enclose my date string in quotes in the where
cleause.

The error is:
Microsoft JET Database Engine: Data type mismatch in criteria expression.

If I remove the quotes and use MyDateVar.ToSho rtDateString the select
executes but ignores the date in the resulting dataset. I get all dates.

Here is my select as it goes into the OleDbDataAdapte r:
select * from TableA where ClientId = 1 and RecDate between '7/15/2003
12:00:00 AM' and '7/15/2003 11:59:59 PM'

This select gives me the above error. I get the error even if I use
ToShortDateStri ng if the date is quoted. I never had a problem with this
using VS.NET2002 and SqlClients.

This is VS.NET2003 and an Access database.

Any help or insight would be greatly appreciated.

Thanks,
Jim
Nov 13 '05 #1
2 5160
"Jim H" <ji*@nospam.now here.com> wrote in
news:Oi******** ******@tk2msftn gp13.phx.gbl:
I'm trying to get a bunch of records based on client id and a
date range. I keep getting an error when I enclose my date
string in quotes in the where cleause.

The error is:
Microsoft JET Database Engine: Data type mismatch in criteria
expression.

If I remove the quotes and use MyDateVar.ToSho rtDateString the
select executes but ignores the date in the resulting dataset.
I get all dates.

Here is my select as it goes into the OleDbDataAdapte r:
select * from TableA where ClientId = 1 and RecDate between
'7/15/2003 12:00:00 AM' and '7/15/2003 11:59:59 PM'

This select gives me the above error. I get the error even if I
use ToShortDateStri ng if the date is quoted. I never had a
problem with this using VS.NET2002 and SqlClients.

This is VS.NET2003 and an Access database.


Jim,

http://msdn.microsoft.com/library/en.../acfundsql.asp

In MS Access SQL, wrap date literals with #:

select * from TableA where ClientId = 1 and RecDate between
#7/15/2003 12:00:00 AM# and #7/15/2003 11:59:59 PM#

If you use OleDbParameters , you don't have to provide the # wrapping:

string sql =
"select * from TableA where ClientId = 1 and RecDate " +
"between @firstDate and @secondDate";

OleDbParameter firstDateParam =
new OleDbParameter( "@firstDate ", OleDbType.DBDat e);
firstDateParam. Value = new DateTime(2003, 15, 7, 12, 0, 0);
firstDateParam. Direction = ParameterDirect ion.Input;

// Similar code for @secondDate...

OleDbCommand command = new OleDbCommand(sq l, connection);
command.Paramet ers.Add(firstDa teParam);
command.Paramet ers.Add(secondD ateParam);
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 13 '05 #2
Another thing you might want to keep in mind is the Universal Date / Time
Format
Being
yyyy-mm-dd hh:mm:ss
(24 hour clock)
This has solved datetime problems in the past for me. Wrapping it in single
quotes should not only be acceptable but necessary for access.
HTH
JB
"Jim H" <ji*@nospam.now here.com> wrote in message
news:Oi******** ******@tk2msftn gp13.phx.gbl...
I'm trying to get a bunch of records based on client id and a date range. I keep getting an error when I enclose my date string in quotes in the where
cleause.

The error is:
Microsoft JET Database Engine: Data type mismatch in criteria expression.

If I remove the quotes and use MyDateVar.ToSho rtDateString the select
executes but ignores the date in the resulting dataset. I get all dates.

Here is my select as it goes into the OleDbDataAdapte r:
select * from TableA where ClientId = 1 and RecDate between '7/15/2003
12:00:00 AM' and '7/15/2003 11:59:59 PM'

This select gives me the above error. I get the error even if I use
ToShortDateStri ng if the date is quoted. I never had a problem with this
using VS.NET2002 and SqlClients.

This is VS.NET2003 and an Access database.

Any help or insight would be greatly appreciated.

Thanks,
Jim

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1193
by: Morten Gulbrandsen | last post by:
C:\mysql\bin>mysql -u elmasri -pnavathe company Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 29 to server version: 4.1.0-alpha-max-debug Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> select database(); +------------+ | database() | +------------+
8
1870
by: Riegnman | last post by:
Hey guys, I'm in need of a little help. I am very new to access but have been trying to learn. My problem is as follows. . . We have time clocks that dump the badge punches into a .log file on one of the servers. I then use access to import these .log files and separate the data into various tables so that I can manipulate it. The problem is that the time clock just records punches and not "in" and "out" times. The data that comes...
0
6782
by: NOSPAM | last post by:
Guys, I get the 'There was an error executing the command' error message. I an using win xp & Access 2002. I created a database using the MS Access template 'Order Entry' I have entered about 97 customer enries so far.
3
3105
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn =server.createobject("ADODB.connection") objConn.open "DSN=Photo" Dim sqlSELsite,ObjRSSel sqlSELsite = "SELECT Name FROM tblbwday WHERE B'day ="& date() &" " '
6
3479
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am using MS-Access 2000 database table for this app. Note that the datatype of all the fields mentioned above are Text. Apart from the above columns, there's another column in the DB table named 'RegDateTime' whose datatype is Date/Time which is...
2
3391
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
8
1955
by: nishkrish | last post by:
Hi, I am new to access I created the form and report from Allen Browne's Frmwhat Date the way he has described but when i preview report it shows StartDate: name? Enddate: name? am i suppose to attach this form or report to some table or query if so how
1
7122
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that someone who bothers to read all of it have some pointers. Note, I have posted the stack trace and the code exhibiting the problem further down so if you want to start by reading that, search for +++ Also note that I am unable to reproduce...
1
3194
by: sphinney | last post by:
All, I'm not sure how to adequately explain my problem in two sentences or less, so at the risk of providing TMI, here's the condensed verion. I have developed an Access 2002 database file that contains a form, multiple queries and multiple reports. The purpose of the form is to allow the user to run various queries against my company's Sybase server and display a report. Since the queries return ADO recordsets from the Sybase server,...
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3960
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.