【问题标题】:unclosed quotation mark after the character string sql server字符串 sql server 后的非闭合引号
【发布时间】:2016-03-21 09:58:57
【问题描述】:

我正在尝试让 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);
}

我不确定如何修复此错误。任何帮助都会很棒。

【问题讨论】:

  • 也许您使用了错误的语言?因为您显示的代码不是有效的 C++。
  • 这不是 C++(我一无所知)但是 ` where Customer_Name = '" + this -> txtName -> Text + ",);"` 看起来很可疑。@ 的单引号987654322@ 没有关闭。
  • 对不起,代码是视觉 C++。我之前在不同的程序中使用过相同的代码并且它有效。这两个程序的唯一区别是我第一次使用 MySQL 而这个程序只使用 SQL。

标签: sql-server visual-c++


【解决方案1】:

您的查询确实有错误。 where 部分缺少引号。

而不是

"' where Customer_Name = '" + this -> txtName -> Text + "**,);**"

你应该写

"' where Customer_Name = '" + this -> txtName -> Text + "**';**"

【讨论】:

  • 是的,修复了它。谢谢。
猜你喜欢
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 1970-01-01
  • 2017-12-19
  • 2019-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多