Click here to Skip to main content
11,928,078 members (48,111 online)
Rate this:
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 20:08pm
Edited 13-Feb-13 20: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!
Smile | :)

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 | Mobile
Web01 | 2.8.151126.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