Example:
INSERT INTO table.Diagnosis([DESCRIPTION]) VALUES('person's')
How can insert it?
Example:
INSERT INTO table.Diagnosis([DESCRIPTION]) VALUES('person's')
How can insert it?
'Person's'
should actually be 'Person''s'
. SQL Server thinks the string ends with that second single quote, so you have to "escape" it with an additional quote.
So your code as-is thinks it's trying to insert "Person"
and anything after this is gibberish to SQL Server.
You'll need to modify your statement to the following:
INSERT INTO table.Diagnosis([DESCRIPTION]) VALUES('person''s')
Because you have tagged this as C# I think that you want to set this value through code.
If this is the case then you probably have a string concatenation that ignores the presence of the single quote.
Something like this
string descValue = "person's";
string cmdText = "INSERT INTO table.Diagnosis([DESCRIPTION]) VALUES(" + descValue +")";
To avoid this problem you should use a parameterized query like this
string descValue = "person's";
string cmdText = "INSERT INTO table.Diagnosis([DESCRIPTION]) VALUES(@desc)";
using(SqlConnection cnn = new SqlConnection(connectionString))
using(SqlCommand cmd = new SqlCommand(cmdText, cnn))
{
cnn.Open();
cmd.AddWithValue("@desc", descValue);
cmd.ExecuteNonQuery();
}
Using a parameterized query shifts the job to use your values to the database engine that now could correctly prepare your values and not blindly run the sql as is. This is true also for other types of values like decimals and dates. Last but not least, a parameterized query is the only way to avoid an Sql Injection attack
Escape single quote with an additional single
INSERT INTO table.Diagnosis([DESCRIPTION]) VALUES('person''s')