我想手动创建一个 ID 字段,我在其中执行 MAX + 1,并且我想在一个 QUERY 中执行它,所以我确定 2 个条目无法获得相同的字段。
using (MySqlConnection dbConn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ProjektConStr"].ConnectionString))
{
dbConn.Open();
using (MySqlCommand cmd = new MySqlCommand("INSERT INTO Submission (CaseId , SubjectId, CenterId, EmployeeName, Reason, Description, Explanation, Date, Done, ChiefLevel) VALUES (MAX(CaseId)+1, @subject_id, @center_id, @employee_name, @reason, @description, @explanation, @date, @done, @chief)", dbConn))
{
cmd.Parameters.AddWithValue("date", submission.Date);
cmd.Parameters.AddWithValue("subject_id", submission.SubjectId);
cmd.Parameters.AddWithValue("center_id", submission.CenterId);
cmd.Parameters.AddWithValue("employee_name", submission.EmployeeName);
cmd.Parameters.AddWithValue("reason", submission.Reason);
cmd.Parameters.AddWithValue("description", submission.Description);
cmd.Parameters.AddWithValue("explanation", submission.Explanation);
cmd.Parameters.AddWithValue("done", false);
cmd.Parameters.AddWithValue("chief", false);
cmd.ExecuteNonQuery();
}
}