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

this code displays result if any one field matches with the records in d/b

but i am getting an Exception...

' Data type mismatch in criteria expression.'
C#
DataTable dt = new DataTable();

string custname = cust_name_txt.Text.ToString();

Int32 chassi, engine;


bool result = Int32.TryParse(cust_chassi_no_txt.Text, out chassi);
bool res2 = Int32.TryParse(sales_engine_no_txt.Text, out engine);

string month = sale_month_cmb.Text;

OleDbDataAdapter da = new OleDbDataAdapter("select * from  sales WHERE [Customer Name] = '" + custname + "' OR [Chassi Number] = '" + chassi + "' OR [Engine Number] = '" + engine + "' OR  [Month of Sale] = '" + month + "' ", con);


con.Open();

da.Fill(dt);              //Data type mismatch in criteria expression. occurs here..
dataGridView1.DataSource = dt;

con.Close();

all the datatypes in D/B are proper.i am using MS Access for database..

can someone please help me with this exception...
Posted
Updated 13-Feb-13 19:25pm
v2
Comments
Shubh Agrahari 14-Feb-13 1:25am    
friend this error generally occurs when we does not using proper data type for proper values from front end to back end........so plz once more revise your data types properly my doubt on your month column....
lukeer 14-Feb-13 1:28am    
To improve potential helpers' reading experience, please wrap code in
<pre lang="c#">YourCodeHere();</pre> (Done for you this time).

 
Share this answer
 
if [Month of Sale]
[Engine Number]
[Chassi Number]
are integer field...

Check you are passing correct values e.g. if [Month of Sale] is int column and you are passing '1 ' then it will cause error you can not pass char or even space in int column
so, you should pass '1'

Happy Coding!
:)
 
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