【发布时间】:2022-09-27 10:46:26
【问题描述】:
这是我编写的代码,但即使在成功的 messageBox 之后它也不会更改数据库中的任何数据
connection.Open();
command = new OleDbCommand(\"UPDATE employeeTable SET fullname=@fullname, [gender]=@gender, [dept]=@dept, [sector]=@sector, [sub_sector]=@sub_sector, [timetable]=@timetable WHERE empid=@empid\", connection);
command.Parameters.AddWithValue(\"@empid\", txtEmpID.Text);
command.Parameters.AddWithValue(\"@fullname\", txtName.Text);
command.Parameters.AddWithValue(\"@gender\", cboGender.SelectedItem.ToString());
command.Parameters.AddWithValue(\"@dept\", cboCompany.SelectedItem.ToString());
command.Parameters.AddWithValue(\"@sector\", cboSector.SelectedItem.ToString());
command.Parameters.AddWithValue(\"@sub_sector\", cboSub.SelectedItem.ToString());
command.Parameters.AddWithValue(\"@timetable\", cboTimetable.SelectedItem.ToString());
command.ExecuteNonQuery();
connection.Close();
MessageBox.Show(\"Record Updated Successfully!\", \"NEW EMPLOYEE ADDED\", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
-
@empid 在数据表中吗?更新没有向表中添加新记录
-
empid 是每个用户在创建新用户期间拥有的工作 ID。所以每个员工都有不同的ID。所以我想用它来选择表就是为什么。但无论更新是否成功保存,它都不会在数据库中更新
标签: c# database ms-access sql-update