Click here to Skip to main content
12,757,627 members (36,522 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
Hello, I have an MS ACCESS table with two columns named item_nm(text) and item_id(This column is autonumber). Whenever I"m trying to update table it's getting an error("Data type mismatch in criteria expression"). Please solve this quest. Thanks!!!!

private void button2_Click(object sender, EventArgs e)
        {
                cn.Open();
                OleDbCommand cm = new OleDbCommand("update tbl_purchaseitementry set item_nm='@item_nm' where item_id='@item_id'", cn);
                cm.Parameters.AddWithValue("@item_nm",txt_itemname.Text);
                cm.Parameters.AddWithValue("@item_id",txt_itemid.Text);
                OleDbDataAdapter da = new OleDbDataAdapter(cm);
                cm.ExecuteNonQuery();
                cn.Close();
        }
Posted 15-Feb-13 4:27am
Updated 15-Feb-13 4:35am
phil.o88K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Take off the quotes:
OleDbCommand cm = new OleDbCommand("update tbl_purchaseitementry set item_nm='@item_nm' where item_id='@item_id'", cn);
Becomes:
OleDbCommand cm = new OleDbCommand("update tbl_purchaseitementry set item_nm=@item_nm where item_id=@item_id", cn);
  Permalink  
Comments
phil.o 15-Feb-13 9:38am
   
Damned, you were faster :)
My 5
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

OleDbCommand cm = new OleDbCommand("update tbl_purchaseitementry set item_nm=@item_nm where item_id=@item_id", cn);


Don't enclose your variables (@item_nm and @item_id) between single quotes ; you don't need to.
  Permalink  

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
Web02 | 2.8.170217.1 | Last Updated 15 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