Using .Net 4.0, C#.
I'm building custom sql in my application that is delivered to a stored procedure on the db side, and further handled from there. I need to be able to put double-quotes around my aliases for the select clause (because once you use them, you always have to use them). I have this logic created and in place, except that the stringbuilder for my select clause is not properly escaping my double-quotes.
My (cleaned) code:
StringBuilder sb = new StringBuilder();
foreach (var detail in report.CustomReport.PTS_CP_CUSTOM_REPORT_DET)
{
var columnDataType = GetColumnDataType(detail);
sb.Append(", " + detail.PTS_CP_CUSTOM_REPORT_VIEW_DET.COLUMN_NAME + " \"" + detail.DISPLAY_NAME + "\"");
this.ColumnData.Add(colData);
}
return string.Format(SelectTemplate, sb);
The output select statement:
SELECT PO_NUMBER \"PO_NUMBER\", .../* several columns */, CUST_NUM \"CUST_NUM\""
I need those backslashes to disappear. I've tried several ways to fix it:
- Append a .Replace to the return statement and the string variable that it is returned to.
- Switch to using a verbatim (@) approach
- Create mini string variables that hold the " \"" value, and append them instead.
I have also run the return without the string.Format() call, and the problem still occurs.
Nothing seems to work. I've looked here, here, here and a few more places and none of them seem to have an answer. Not sure where to go from here.