0
votes

I'm trying to get my update command in SQL to work. Every time I try to update a record I get the following error unclosed quotation mark after the character string. Here my code:

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

I am not sure how to fix this error. Any help would be great.

1
Perhaps you're using the wrong language? Because the code you showed is not valid C++.Sam Varshavchik
That' s not C++ (and nothing I know) But the ` where Customer_Name = '" + this -> txtName -> Text + ",);"` looks suspicious. The single quote of Customer_Name=' isn't closed.Oncaphillis
Sorry the code is visual C++. I have used the same code before in a different program and it worked. The only difference between the two program is the first I used MySQL and this program in using just SQL.Doe

1 Answers

1
votes

You do have an error in your query. There is a missing quotation mark on the where part.

Instead of

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

you should write

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