tags:

views:

868

answers:

5

I have query build from Visual Studio 2005. I am inserting records from SQL database to Access.

My query is

insert into i_mails
   (id,from_mails,to_mails,cc_mails,subject,body,
    anchor_level_id,attachment,forward_status ,reply_status,delete_status,        read_status, 
   received_date,response_date,
   batch,forward_score,delete_score,priority,
    is_auto_reply,parent_mail_id,case_id,time_bound) 

values (1,'[email protected]',  '[email protected]','[email protected]',  'Hi','--long html field--',
        7 , 'True' ,False,False,False,False,
        #12/12/2000 00:00:00# ,#12/12/2000 00:00:00#,
        0, '0','0',  1 , 
        'False',0,2,0)

I get Data Type Mismatch in criteria expression Error..
Not knowing where this error is firing in Query ... Please Help !!

Access Database Structure:

Id - Number,
from_mails - Memo,
to_mails - Memo,
cc_mails - Memo,
subject - Memo,
body - Memo,
anchor_level_id - Number,
attachment -Yes\No,
forward_status - Yes\No,
reply_status - Yes\No,
delete_status - Yes\No,
read_status - Yes\No,
received_date - DateTime,
response_date - DateTime,
batch - Number,
forward_score - Number, delete_score - Number,
priority - Number,
is_auto_reply - Yes\No,
parent_mail_id - Number,
case_id - Number,
time_bound - Number,

+3  A: 

Replace each value with a null (or other 'zero' value). Start with the first, then the second (leaving the first as null) and on until you have replaced all the values with nulls. test the query after each change.

When the query starts working, the last value you changed is the one that is causing the problem.

P.S. It may not be the only value that is incorrect, but using this method you will find all the badly typed values.

Hope this helps

Binary Worrier
+1. But this will only work if all fields allow null.
Dead account
Ian: I got there before you :) See "or other 'zero' value" above :)
Binary Worrier
Varun Mahajan answer was correct for me..Its working fine now
Girish1984
Thanks for your help guys
Girish1984
The default for fields in a Jet table created from the Access UI is that a field is not required, i.e., it can be Null.
David-W-Fenton
+1  A: 

it's hard to tell without knowing the table structure and datatypes but at a complete guess

the values you're trying to insert into received_date & response_date

are incorrect because of the # symbol delimiters...

try changing them to

'12/12/2000 00:00:00' ,'12/12/2000 00:00:00' 
//i.e. Surround them with apostrophes
Eoin Campbell
i tried..but no luck...
Girish1984
# symbols are how you delimit dates in MS Access.
Binary Worrier
Really... Nasty :(
Eoin Campbell
No, it's not nasty. It's just a different SQL dialect, one that dates back quite a ways when SQL was not nearly as widespread. If you don't like the Jet SQL defaults, then use a data access method that allows you to use ANSI 92 instead of ANSI 89 (which means ADO instead of DAO, for instance).
David-W-Fenton
One workaround is to use CDATE('2000-12-12 00:00:00'), or whatever is your preferred unambiguous format, which is particularly good if you use Access Query objects because the UI changes the #-delimited dates into its own format. And works in all Query Modes :)
onedaywhen
+3  A: 

For is_auto_reply, use 'false' without quotes. This seems to be the problem

Varun Mahajan
How do you know it's not a string?
Dead account
is_auto_reply datatype is "Yes\No" in Access
Girish1984
In that case, you don't want the quotes.
mavnn
Thank you so much ...Its working fine now !!!
Girish1984
It was just an intution. It happens when you start using access as a programming tool ;)
Varun Mahajan
A: 

It might be worth checking if your '-- long html field --' contains any formatting issues (does it contain any apostrophes, for example, which would be interpreted as prematurely ending the field).

Beyond that, what the others said: without details of the table structure, no ones going to be able to help you much.

mavnn
How do i post structure design Here ??
Girish1984
The important information is the data types shown by the design view of the table.
mavnn
+1  A: 

Look at data you're trying to insert into fields: attachment and is_auto_reply They should be boolean valued fields while you're trying to insert string data 'True' and 'False'.

juckobee
i got it right now..Thank you...
Girish1984