Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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.'
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 13-Feb-13 20:08pm
Edited 13-Feb-13 20:25pm
lukeer15K
v2
Comments
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 end........so 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
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 2

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!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Richard MacCutchan 145
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
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