update in ms access using c#

后端 未结 1 520
星月不相逢
星月不相逢 2021-01-29 12:41

can someone please help what is wrong with my code? it is a update function and during my debug it executing properly but it is not updating my database. I already search for an

相关标签:
1条回答
  • 2021-01-29 13:15

    Add the parameters in the correct order as expected by the placeholders

    cmd.Parameters.AddWithValue("@meals", meal.Text);
    int mealPrice = Int32.Parse(price.Text);
    cmd.Parameters.AddWithValue("@price", mealPrice);
    cmd.Parameters.AddWithValue("@picture", savePhoto());
    cmd.Parameters.AddWithValue("@description",description.Text);
    cmd.Parameters.AddWithValue("@id", id1);
    

    OleDb doesn't resolve parameters values by their name, but by the parameter's position in the parameters collection. With your order the id condition in the where clause receives the value from the description parameter.

    Consider also to use Add instead of AddWithValue

    See: Can we stop using AddWithValue already?

    0 讨论(0)
提交回复
热议问题