Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

i am getting an error like
<br />
<br />
Data type mismatch in criteria expression.<br />
<br />

i am using wpf (windows application in C#.net )
iam using the access2003 as the database
i had tried as below

OleDbConnection mcon = new OleDbConnection("provider =Microsoft.JET.OLEDB.4.0;data source=D:\\invoice\\invoice.mdb");
               OleDbCommand da = new OleDbCommand("select companyname,customername from invoicetable where date BETWEEN '&11/11/1975&' AND '&11/11/2004&'  order by ID desc", mcon);
               OleDbDataReader dr;
               mcon.Open();
               dr = da.ExecuteReader();

and also i had trind in this way also
OleDbCommand da = new OleDbCommand("select companyname,customername from invoicetable where date BETWEEN '11/11/1975' AND '11/11/2004'  order by ID desc", mcon);


in access database in am saving in date formate like 'mm/dd/yyyy' in shortformate
what is the error that i am doing, please help me

thankq for ur attention thank's a lot
Posted
Comments
Sunasara Imdadhusen 23-Sep-10 5:08am    
What is the error?

For access use # to represent date. Converting date into yyyy-mm-dd format would be better. Like
select companyname,customername from invoicetable where date BETWEEN #1975-11-11# AND #2004-11-11#  order by ID desc 
 
Share this answer
 
Comments
[no name] 27-Sep-10 7:12am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
Access has a specific notation for date's, I believe you have to put your date between '#' (so #11/11/1975#).

But it would be far better to use parameters for this, you'll protect yourself from SQL-injections (Google it if you don't know what it is).

In this case you'll have to use oledbparameter.
In your SQL string you replace the date's with '?', and then you add your parameters in the correct order to your command.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900