我正在尝试在SQL中使用我的更新命令。每次我尝试更新记录时,我都会在字符串后面得到以下错误的未闭合引号。这是我的代码:
String^ connectionString = L"**********";
SqlConnection^ myCon = gcnew SqlConnection(connectionString);
SqlCommand^ myCommand = gcnew SqlCommand("UPDATE ******* SET Customer_Name = '" + this -> txtName -> Text + "', Customer_Address = '" + this -> txtPhone -> Text + "', Customer_City = '" + this -> txtCity -> Text + "', Customer_State = '" + this -> txtState -> Text + "', Customer_Zip = '" + this -> txtZip -> Text + "', Customer_Phone = '" + this -> txtPhone -> Text + "', Customer_Email = '" + this -> txtEmail -> Text + "' where Customer_Name = '" + this -> txtName -> Text + ",);", myCon);
SqlDataReader^ myReader;
try {
myCon -> Open();
myReader = myCommand -> ExecuteReader();
MessageBox::Show("Updated!!");
}
catch (Exception^ ex) {
MessageBox::Show(ex->Message);
}
我不确定如何解决此错误。任何帮助都会很棒。
答案 0 :(得分:1)
您的查询中确实有错误。 where
部分缺少引号。
而不是
"' where Customer_Name = '" + this -> txtName -> Text + "**,);**"
你应该写
"' where Customer_Name = '" + this -> txtName -> Text + "**';**"