Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!!!!

C#
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
Updated 15-Feb-13 3:35am
v2

C#
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.
 
Share this answer
 
Take off the quotes:
C#
OleDbCommand cm = new OleDbCommand("update tbl_purchaseitementry set item_nm='@item_nm' where item_id='@item_id'", cn);
Becomes:
C#
OleDbCommand cm = new OleDbCommand("update tbl_purchaseitementry set item_nm=@item_nm where item_id=@item_id", cn);
 
Share this answer
 
Comments
phil.o 15-Feb-13 9:38am    
Damned, you were faster :)
My 5

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900