Data type mismatch in criteria expression c#

459 views Asked by At

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?

1

There are 1 answers

2
outstacked On

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.