Answered by:
Quotation mark issue while updating a datagrid..

Question
-
User2140025385 posted
Hi,
My problem is this:
I have a DataGrid, which i use to update some values. My DATABASE is microsoft access.
whenever i try to add text that includes quotation mark to the textbox so i can update a certain values, i get a Syntax error saying:
Syntax error (missing operator) in query expression ''bla bla bla bla..'.....
this is my sql statement for updating the grid
string queryStr = "UPDATE [tours] SET [title] = '" + txtBoxTitle.Text + "', [desc] = '" + txtBoxDesc.Text + "', [photo] = '" + txtBoxPhoto.Text + "' WHERE [id] = '" + txtBoxId.Text + "'";string queryStr = "UPDATE [tours] SET [title] = '" + txtBoxTitle.Text + "', [desc] = '" + txtBoxDesc.Text + "', [photo] = '" + txtBoxPhoto.Text + "' WHERE [id] = '" + txtBoxId.Text + "'";
something is going wrong with the structure of the update statement and the quotation mark i enter in the text. Obviously its confusing the statement.
Any help is really appreciated.
THANKS
Tuesday, July 6, 2010 8:00 PM
Answers
-
User-42918493 posted
txtBoxTitle.Text.Replace("'","''")
use like this...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, July 7, 2010 1:06 AM
All replies
-
User-42918493 posted
txtBoxTitle.Text.Replace("'","''")
use like this...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, July 7, 2010 1:06 AM -
User2140025385 posted
does it scan the whole text in the textbox?
Wednesday, July 7, 2010 10:02 AM -
User2140025385 posted
found it,
txtBoxTitle.Text= txtBoxTitle.Text.Replace("'", "''");
thanks a lot man, u helped me.
Wednesday, July 7, 2010 10:07 AM -
User-1199946673 posted
found it,
txtBoxTitle.Text= txtBoxTitle.Text.Replace("'", "''");
thanks a lot man, u helped me.
Although it may help you, it still is a bad advice. You should start using parameter queries:
http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access
Wednesday, July 7, 2010 2:34 PM