Click here to Skip to main content
11,798,039 members (78,941 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#

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
Edited 13-Feb-13 19:25pm
Shubh Agrahari at 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 at 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!
Smile | :)

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

  Print Answers RSS
0 CPallini 575
1 Maciej Los 375
2 OriginalGriff 353
3 Abhinav S 342
4 Richard MacCutchan 218
0 OriginalGriff 2,150
1 Maciej Los 1,790
2 KrunalRohit 1,456
3 CPallini 1,415
4 Richard MacCutchan 1,016

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
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