目前,我有 private void btnInsertStudentNumberAdmin_Click(object sender, EventArgs e) {
这是我的 m MySqlConnection conn = connection(); conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.tAverage", studentInsert); prevID(conn, cmd); }
您需要更改方法接受附加参数
public static void insertStudent(string personID, string studentNumber,string gradePointAverage , string majorFieldt)
请注意,您需要根据为相关参数提供 n 个数据库的列数据类型来提供正确的类型。例如,如果 personID 在数据库中是整数,则应将参数更改为int personID
使用所有参数更改您的 sql 语句
INSERT INTO student(personID, studentNumber, gradePointAverage , majorField ) VALUES (@personID, @studentNumber, @gradePointAverage , @majorField)
并使用设置参数值
cmd.Parameters.AddWithValue("@personID", personID);
cmd.Parameters.AddWithValue("@studentNumber", studentNumber);
cmd.Parameters.AddWithValue("@gradePointAverage", gradePointAverage );
cmd.Parameters.AddWithValue("@majorField", majorField );
您可以如下调用上述方法
private void btnInsertStudentNumberAdmin_Click(object sender, EventArgs e)
{
studentHelperClass.insertStudent(txtInsertStudentNumber.Text, txtstudentNumber.Text, txtgradePointAverage.Text , txtmajorField.Text );
}