0
con.Open();
cmd = new OleDbCommand("UPDATE staff SET StaffNr = @a, FirstName = @b, 
    Surname = @c, Email = @d, Balance = @e WHERE Email = @d", con);

cmd.Parameters.AddWithValue("@b", textBoxStaffName.Text);
cmd.Parameters.AddWithValue("@c", textBoxStaffSur.Text);
cmd.Parameters.AddWithValue("@d", textBoxStaffE.Text);
cmd.Parameters.AddWithValue("@e", double.Parse(textBoxSatffBal.Text));
cmd.Parameters.AddWithValue("@a", int.Parse(textBoxStaffNr.Text));
cmd.ExecuteNonQuery();
con.Close();

由于某种原因没有更新数据库,但代码运行

4

1 回答 1

0

OldDb?用于参数,而不是@x. 您必须按顺序添加参数。名称被忽略AddWithValue(此方法来自通用超类)

con.Open();
cmd = new OleDbCommand("Update staff set StaffNr = ?, FirstName = ?, 
    Surname = ?, Balance = ? Where Email = ?", con);

cmd.Parameters.AddWithValue("@a", int.Parse(textBoxStaffNr.Text));
cmd.Parameters.AddWithValue("@b", textBoxStaffName.Text);
cmd.Parameters.AddWithValue("@c", textBoxStaffSur.Text);
cmd.Parameters.AddWithValue("@e", double.Parse(textBoxSatffBal.Text));
cmd.Parameters.AddWithValue("@d", textBoxStaffE.Text);
cmd.ExecuteNonQuery();
con.Close();
于 2013-10-27T16:48:23.743 回答