简体   繁体   中英

Data type mismatch in criteria expression c#

The following exception is thrown when I run the below code:

system.data.oledb.oledbexception data type mismatch in criteria expression

private void buttonUp_Click(object sender, EventArgs e)
{
    try
    {
        connection.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        string query = "UPDATE data SET  Name ='"+txtNL.Text+"' , Period ='"+txtper.Text+"' , DOB = '"+txtmonth.Text+"', price = '"+txtprice.Text+"', follow = '"+combofw.Text+"' WHERE ID = "+txtid.Text+" ";
        //(ID,Name,Period,DOB,price,follow)
        MessageBox.Show(query);
        command.CommandText = query;

        command.ExecuteNonQuery();
        MessageBox.Show("Data Edited/Updated Successful");
        connection.Close();
    }
    catch (Exception ex)
    { MessageBox.Show("Error " + ex); }
}

How can I fix this?

One of your inputs does not match the data type that the database table is expecting. For example if you pass"abbx" as the date text and your table is expecting DateTime, it's not going to work. Make sure you match the types in your input to the one your table has.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM