Click here to Skip to main content
15,867,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a question.

I have to insert oracle table values in Access database.

I am storing oracle table values in datatable(dt).

In oracle and Access database "Net" field is a "Number"

Trying to insert "Net" field in access datatype i am getting following exception.
"Data type mismatch in criteria expression."

I have found out the reason is "Net" field value in oracle table is EMPTY ("").

What i did is trying to check the field IsNullOrEmpty, if it is Empty then i want to store null value into "Net" field(In Access database).

I have made some code change after that also receiving the same error message .

""Data type mismatch in criteria expression."

Please help me how to fix this.

What I have tried:

strNet = !string.IsNullOrEmpty(dr["NET"].ToString()) ? dr["NET"].ToString() : null;
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
sInsertValues= "'" + strNet + "'";

insertAEdetails.ParmValue = sInsertValues;

insertAEdetails.InsertIntoAccess();
iNbrInserts++;
}
}
Posted
Updated 16-Nov-17 5:52am
v2
Comments
ZurdoDev 16-Nov-17 11:23am    
It looks like you are doing dynamic sql which means you would need to change null to the string "null", right? But then you won't want single quotes around it.
sai.2012 16-Nov-17 11:44am    
I tried strNet = !string.IsNullOrEmpty(drAEDetails["NET"].ToString()) ? drAEDetails["NET"].ToString() : "Null";
but still i am getting same error message.

Thanks for the reply
Karthik_Mahalingam 17-Nov-17 1:39am    
use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Bryian Tan 16-Nov-17 12:34pm    
have you try DBNull.Value? Assuming dr is the DataReader in this context

var strNet = dr["NET"] != DBNull.Value ? dr["NET"].ToString() : null;

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