Link to home
Start Free TrialLog in
Avatar of Phil Catterall
Phil Catterall

asked on

C# code with a SQL string is converting single quotes to 2 single quotes.

I have a bit of code as below, and for some strange reason the actual code issued to SQL server has all of the single quotes replaced with 2x single quotes. Not by my code though. Any thoughts anyone ?
C# code
string sql = @"SELECT TOP 1 isnull(rtrim(JCI.joco_FirstName), '''' ) WHERE Case_CaseId = @CaseId;";
     // execute
     using (SqlDataAdapter da = new SqlDataAdapter(sql.ToString(), connection))
     {
         da.SelectCommand.Parameters.AddWithValue("@CaseId", JobId);
         da.Fill(dtDetail);
     }


Actual SQL issued (via SQL Profiler trace)
exec sp_executesql N'SELECT TOP 1 isnull(rtrim(JCI.joco_FirstName), '''''''' ) WHERE Case_CaseId = @CaseId;',N'@CaseId int',@CaseId=2237361

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Phil Catterall
Phil Catterall

ASKER

Perfect. Simples !!
Thanks