Csharp/C#教程:在更新期间执行命令期间遇到致命错误分享


在更新期间执行命令期间遇到致命错误

我使用此代码更新文本框中的数据…此代码位于更新按钮中,一旦我进行更改并单击按钮,就会出现错误消息

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); } 

登记此行

  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#学习教程:在更新期间执行命令期间遇到致命错误分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/988626.html

(0)
上一篇 2021年12月24日
下一篇 2021年12月24日

精彩推荐