有人可以告诉我为什么下面的代码在字符串之前和之后添加了 2 个单引号('' string '')?
List<string> rolls
StringBuilder sb = new StringBuilder();
foreach (var roll in rolls)
sb.Append("'" + roll + "',");
string rollList = sb.ToString().TrimEnd(',');
string sql =
@"SELECT enrolment_status, roll_number FROM dt_modular_enrolment WHERE id_student = ?
AND roll_number in " + "( " + rollList + " )";
creates the below:
in ( ''ROLL4'',''ROLL6'',''ROLL5'',''ROLL1'',''ROLL2'',''ROLL3'' )
谢谢!
只是为了更新 - 代码没有任何问题(除了 sql 注入的可能性)它是一个 sql profiler bug 添加了额外的引号。