更新过程中命令执行过程中遇到致命错误 [英] fatal error encountered during command execution during update
本文介绍了更新过程中命令执行过程中遇到致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码更新是在文本框中数据...此代码是在更新按钮,一旦我所做的更改并点击出现错误消息的按钮
块引用>
试
{
的MySqlConnection连接=新的MySqlConnection(MyConnectionString);
的MySqlCommand CMD;
connection.Open();
CMD = connection.CreateCommand();
cmd.CommandText =UPDATE student_info SET SEM = @SEM,STUDENT_NO = @STUDENT_NO,姓氏= @LASTNAME+
,名字= @FIRSTNAME,中间名= @MIDDLENAME,CITY = @CITY,街道= @STREET,性别= @GENDER+
,当然= @COURSE,YEAR = @YEAR,SECTION = @SECTION,生日= @BIRTHDAY其中STUDENT_NO = @STUDENT_NO;
cmd.Parameters.AddWithValue(@ SEM,sem_combo.Text);
cmd.Parameters.AddWithValue(@ STUDENT_NO,studentNo_txt.Text);
cmd.Parameters.AddWithValue(@姓氏,lname_txt.Text);
cmd.Parameters.AddWithValue(@名字,fname_txt.Text);
cmd.Parameters.AddWithValue(@中间名,mname_txt.Text);
cmd.Parameters.AddWithValue(@ CITY,address_txt.Text);
cmd.Parameters.AddWithValue(@街,street_txt.Text);
cmd.Parameters.AddWithValue(@性别,gender_combo.Text);
cmd.Parameters.AddWithValue(@课程,program_combo.Text);
cmd.Parameters.AddWithValue(@ YEAR,yr_combo.Text);
cmd.Parameters.AddWithValue(@段,section_combo.Text);
cmd.Parameters.AddWithValue(@你生日快乐,bday.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText =UPDATE联系人设置电子邮件= @EMAIL,CELL_NO = @CELL_NO其中STUDENT_NO = @STUDENT_NO;
cmd.Parameters.AddWithValue(@ EMAIL,email_txt.Text);
cmd.Parameters.AddWithValue(@ CELL_NO,contact_txt.Text);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
赶上(异常前)
{
MessageBox.Show(ex.Message);
}
解决方案检查在此行
cmd.Parameters.Clear();
cmd.CommandText =UPDATE联系人设置电子邮件= @EMAIL,
CELL_NO = @CELL_NO其中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联系人设置电子邮件= @EMAIL,
CELL_NO = @CELL_NO其中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
参数。清除后疗法参数
此参数不会宣布任何地方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); }
解决方案Check in This Line
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();
Change To
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();
you are clear the parameters, but after that use
@STUDENT_NO
parameter. This parameter is not declare any where after clear ther parameters这篇关于更新过程中命令执行过程中遇到致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文