C# - I have a sql string that I am using with string.format. I need to put single quotes around the parameter {1} which returns 'OUTFALL 002'. SO the string would need to look like this:
and smp.sys_loc_code = 'OUTFALL 002'
I am trying this
and smp.sys_loc_code = \'{1}\'
but it keeps giving me this error message:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Incorrect syntax near 'OUTFALL 002\'.
Source=.Net SqlClient Data Provider
StackTrace:
<Cannot evaluate the exception stack trace>
Below is the query:
var names = string.Format(@"select distinct ........
and smp.sys_loc_code = \'{1}\' ......
", var1, var2)).ToList();
What am I doing wrong?
User contributions licensed under CC BY-SA 3.0