gpt4 book ai didi

c# - 更新期间执行命令时遇到 fatal error

转载 作者:行者123 更新时间:2023-11-29 06:39:30 25 4
gpt4 key购买 nike

i use this code to update data that are in the textboxes... this code is in the update button and once i made the changes and clicked the button the error message appears

        try
{
MySqlConnection connection = new MySqlConnection(MyConnectionString);
MySqlCommand cmd;
connection.Open();
cmd = connection.CreateCommand();
cmd.CommandText = "UPDATE student_info SET SEM = @SEM, STUDENT_NO = @STUDENT_NO, LASTNAME = @LASTNAME" +
", FIRSTNAME = @FIRSTNAME, MIDDLENAME = @MIDDLENAME, CITY = @CITY, STREET = @STREET, GENDER = @GENDER" +
", COURSE = @COURSE, YEAR = @YEAR, SECTION = @SECTION, BIRTHDAY = @BIRTHDAY Where STUDENT_NO = @STUDENT_NO";

cmd.Parameters.AddWithValue("@SEM", sem_combo.Text);
cmd.Parameters.AddWithValue("@STUDENT_NO", studentNo_txt.Text);
cmd.Parameters.AddWithValue("@LASTNAME", lname_txt.Text);
cmd.Parameters.AddWithValue("@FIRSTNAME", fname_txt.Text);
cmd.Parameters.AddWithValue("@MIDDLENAME", mname_txt.Text);
cmd.Parameters.AddWithValue("@CITY", address_txt.Text);
cmd.Parameters.AddWithValue("@STREET", street_txt.Text);
cmd.Parameters.AddWithValue("@GENDER", gender_combo.Text);
cmd.Parameters.AddWithValue("@COURSE", program_combo.Text);
cmd.Parameters.AddWithValue("@YEAR", yr_combo.Text);
cmd.Parameters.AddWithValue("@SECTION", section_combo.Text);
cmd.Parameters.AddWithValue("@BIRTHDAY", bday.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();

cmd.CommandText = "UPDATE contacts SET EMAIL = @EMAIL, CELL_NO = @CELL_NO Where STUDENT_NO = @STUDENT_NO";

cmd.Parameters.AddWithValue("@EMAIL", email_txt.Text);
cmd.Parameters.AddWithValue("@CELL_NO", contact_txt.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

最佳答案

checkin 此行

            cmd.Parameters.Clear();

cmd.CommandText = "UPDATE contacts SET EMAIL = @EMAIL,
CELL_NO = @CELL_NO Where STUDENT_NO = @STUDENT_NO";

cmd.Parameters.AddWithValue("@EMAIL", email_txt.Text);
cmd.Parameters.AddWithValue("@CELL_NO", contact_txt.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();

更改为

            cmd.Parameters.Clear();
cmd.CommandText = "UPDATE contacts SET EMAIL = @EMAIL,
CELL_NO = @CELL_NO Where STUDENT_NO = @STUDENT_NO";

cmd.Parameters.AddWithValue("@EMAIL", email_txt.Text);
cmd.Parameters.AddWithValue("@CELL_NO", contact_txt.Text);
cmd.Parameters.AddWithValue("@STUDENT_NOL",studentNo_txt.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();

您已清除参数,但之后使用@STUDENT_NO 参数。此参数在清除参数后不在任何地方声明

关于c# - 更新期间执行命令时遇到 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22351793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com