Can anyone tell me where my error is I can't seem to find it..


Thanks,

Penguin

Code Snippet

"UPDATE AddressEntry SET Cell = \'" + txtCell.Text + "\', Home = \'" + txtHome.Text + "\', Work = \'" + txtWork.Text + "\', Name = \'" + txtName.Text + "\', Address = \'" + txtAddress.Text + "\', City = \'" + txtCity.Text + "\', State = \'" + txtState.Text + "\', Zip = \'" + txtZip.Text + "\', E_mail = \'" + txtEmail.Text + "\' WHERE ID = \'" + entry.EntryID + "\'";

Edited 6 Years Ago by penguin22: n/a

Hello penguin22,
is ID field in your datatable INT? WHERE statement in your query looks like STRING datatype.

...
WHERE ID = " + entry.EntryID.ToString();

Cheers

Can anyone tell me where my error is I can't seem to find it..


Thanks,

Penguin

Code Snippet

"UPDATE AddressEntry SET Cell = \'" + txtCell.Text + "\', Home = \'" + txtHome.Text + "\', Work = \'" + txtWork.Text + "\', Name = \'" + txtName.Text + "\', Address = \'" + txtAddress.Text + "\', City = \'" + txtCity.Text + "\', State = \'" + txtState.Text + "\', Zip = \'" + txtZip.Text + "\', E_mail = \'" + txtEmail.Text + "\' WHERE ID = \'" + entry.EntryID + "\'";

it gives error where you use '\' first remove it so your code will run sucessfully. if you want then write your code like this

UPDATE [AddressEntry] SET [Cell] = '\" + txtCell.Text + "\', [Home] = '\" + txtHome.Text + "\', [Work] = '\" + txtWork.Text + "\', [Name] = '\" + txtName.Text + "\', [Address] = '\" + txtAddress.Text + "\', [City] = '\" + txtCity.Text + "\', [State] = '\" + txtState.Text + "\', [Zip] = '\" + txtZip.Text + "\', [E_mail] = '\" + txtEmail.Text + "\' WHERE [ID] = '\" + entry.EntryID.ToString() + "\' “;

Edited 6 Years Ago by pritesh2010: n/a

pritesh...what you have suggested is completely wrong. HOW he used the '/' is absolutely right, it was WHERE he used it that is the problem. If EntryID is a numeric data type then it should not be enclosed as a string.

The '/' is an escape sequence that ensures the compiler reads the ' as a literal ' character and not a part of the code.

pritesh...what you have suggested is completely wrong. HOW he used the '/' is absolutely right, it was WHERE he used it that is the problem. If EntryID is a numeric data type then it should not be enclosed as a string.

The '/' is an escape sequence that ensures the compiler reads the ' as a literal ' character and not a part of the code.

yes in my example only the where condition i had writtn wrong but other wise it is true if AddressEntry table contain all the varchar datatype then it will work for wild card charecters('\'). otherwise if the table contain numeric ordattime then it will not except '\' this charcters. and @ the end in where Condition should be like this
Where Id='" entry.EntryId "'

Comments
a mistake is forgivable...an argument founded in ignorance is not

No, in your example you had written MOST of it wrong. You have switched the position of the \.
Correct way: \'
Your way: '\

The \ marks the beginning of an escape sequence. The compiler then treats the following characters as part of the escape sequence. \' is the escape sequence for a literal ' character. Heres one example from YOUR code: SET [Cell] = '\" + txtCell.Text the highlighted section shows the problem. Instead of escaping the ' you have escaped the ". So the compiler treats it as a literal " instead of the end of the string. So the next part, the variable, is inserted as a straight string.

What possible reason could there be to switch the escape sequence around?

Hi penguin, can you clarify for me: What datatype is the [ID] field in your [AddressEntry] table in the database? is it a numeric type (int/numeric/etc) or a string type(varchar/nvarchar/etc)?

it is in microsoft access as STRING do you think it could possibly be because of the string containing hyphens(-) this is being built via visual studio

ok, if evertyhing is string based then i cant see where you might be going wrong. What error are you getting exactly?

It tells me OleDb Exception Update syntax error the entry id is a Guid.toString() i.e 86b3bf25-be1f-46fc-acd9-2a8aa7c60cac as a string

OleDb Exception Update syntax incorrect (or something to that nature) my EntryId as a string contains hyphens (-) would that possibly be the problem

Its very possible you have used a reserved word for a field name (Name is one i beleive).
Try putting square bracers around all of the field names:

"UPDATE [AddressEntry] SET [Cell] = \'" + txtCell.Text + "\', [Home] = \'" + txtHome.Text + "\', [Work] = \'" + txtWork.Text + "\', [Name] = \'" + txtName.Text + "\', [Address] = \'" + txtAddress.Text + "\', [City] = \'" + txtCity.Text + "\', [State] = \'" + txtState.Text + "\', [Zip] = \'" + txtZip.Text + "\', [E_mail] = \'" + txtEmail.Text + "\' WHERE [ID] = \'" + entry.EntryID + "\'";

Will do when chance comes up. Currently at work and do not have the program with me. Will update you guys when tried.. Thanks

This question has already been answered. Start a new discussion instead.