-
February 7th, 2008, 02:10 AM
#1
Error
SQLSERVER2000
----------------------
Dear All,
I want to update to a table field. I use
Query= 'Select 'c' distinct S.Name'.
i want to enter a varchar value like that having 'c' inside but sqlserver give me an error.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'c'.
update AllQueryFields set Query= 'Select 'c' distinct S.Name '
Where ObjectName ='0303' and FieldAlias='Status'
how i can enter that value
-
February 7th, 2008, 02:38 AM
#2
Re: Error
Don't put the column name in quotes. Just use it as:
SELECT c FROM [table]
-
February 7th, 2008, 06:27 AM
#3
Re: Error
For example
----------------
update AllQueryFields set t = replace('you can ''c'' me','''','`')
Where ObjectName ='0303' and FieldAlias='Status'
this code is working but if a user must enter two times single quote then enter one time single quote in the database.
for example if a user enter in a textbox
you can 'c' me ..... he must be type
you can ''c'' me
then single quote enter in the database.
Any suggestion for correct my code????
thanks
-
February 7th, 2008, 11:15 AM
#4
Re: Error
Don't expect the user to fix the issue, when the user types an singlequotes into a field that goes into a databse, you need to replace the singlequote with two singlequotes.
For example: a user enters this into a textbox...
Code:
I want to enter 'this' into the database
You need to replace the singlequotes with two singlequotes before you place it into your sql command.
Code:
string sqlQuery = "update sometable set somefield = '" + textBox1.Text.Replace("'", "''") + "'";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|