Click here to Skip to main content
13,139,132 members (62,855 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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.'
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);

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

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

can someone please help me with this exception...
Posted 13-Feb-13 19:08pm
Updated 13-Feb-13 19:25pm
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 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).
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

[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!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100