Reputation: 422
I have a table in my SQL Server database with a column of type nvarchar(50)
;
I tried to do this:
Right click on my table
Selecting "Edit 200 first rows"
Typing in that column 'a'
I get an error like this:
Error source: .Net SqlClient Data Provider.
Error message: Incorrect syntax near 'a'.
Correct the errors and retry".
Why do I get this error message and how can I fix this?
Upvotes: 0
Views: 3652
Reputation: 1
I have had the same error.
I want to insert a value I am Nam 'ABC'
into MyTable
at field Description
as following SQL statement
Insert Into table MyTable (Description) values('I am Nam 'ABC'');
Once Insert
command executed the error occur immediately
Incorrect syntax near 'ABC'.
Note that the reason why is SQL will understand character " ' "
which before ABC
belongs to character
" ' "
before I
, and one after ABC belongs to " ' "
at the end. As a result ABC
does not belong to SQL
statement anymore therefore it makes a break of statement.
Here is my solution:
I added two single quotes for each side of ABC
Insert Into table MyTable (Description) values('I am Nam ' 'ABC' ' ');
Upvotes: 0
Reputation: 715
I have used aqua data studio and tested this it is allowing me.
my result:::
id testc
----- ---------
1 'asdfasd'
If you want to use it thrugh .net then while passing the string add the escape sequences. suppose if you are sending "'"--single quote.. then send I have used and tested this it like "\'" is allowing me.
refer below link:::
http://www.codeproject.com/Questions/157918/How-can-I-insert-a-special-character-in-sql-server
Upvotes: 2