escape ' (single quote)

Posts   
 
    
S
User
Posts: 7
Joined: 13-Feb-2007
# Posted on: 19-Feb-2007 05:10:58   

I apologize - the exception was being thrown at a different piece of code.

How do I insert "S's Test" to a text field in database? Below is the piece of code I currently have, where single quote is replaced by 2 single quotes before save. Unfortunately this sets the value as "S''s Test".
On the other hand if I try to insert the value as it is, I get the error message - "Syntax Error - Missing operand after 's' operator".

So how do I escape single quote and other special characters?

CodeEntity cdEnt = FetchCodeEntity(codeListEnt, codeListEnt.Code, value, true); cdEnt.ClinCodeValue = value.Replace("'", "''"); cdEnt.OdsUpdateDate = DateTime.Now; cdEnt.SrcCreateDate = DateTime.Now; cdEnt.SrcUpdateDate = DateTime.Now; cdEnt.SrcSysId = -1; cdEnt.SrcDeleteInd = "N"; bool saved = _adapter.SaveEntity(cdEnt, false);

Thanks for your help, S.