如何在包含变量的逐字字符串中转义双引号
How I can escape a double quote in a verbatim string that contains variables
我有一些包含变量的逐字字符串,我的问题是我总是从编译器中得到这个错误:
; expected
那我怎么才能正确转义呢?
int teacherId = sqlStatus = (int)sqlCmd.LastInsertedId;
sqlCmd.CommandText = @"INSERT INTO report (report_type, report_date, semester, report_details, teacher_id)
VALUES (0, ""2018-01-01"", 1, '{
""teacherId"": "" " + teacherId.ToString() + " "", <=== error here (; expected)
""mahderDate"": """",
""teacherShool"": """",
""baladia"": """",
""wilaya"": """",
""moufatecheReport"": """"
}'," + teacherId + ");";
使用@poke 的建议,我设法通过在行中放置双引号和@ 使其工作:
int teacherId = sqlStatus = (int)sqlCmd.LastInsertedId;
sqlCmd.CommandText = @"INSERT INTO report (report_type, report_date, semester, report_details, teacher_id)
VALUES (0, ""2018-01-01"", 1, '{
""teacherId"": "" " + teacherId.ToString() + "," +
@" ""mahderDate"": """",
""teacherShool"": """",
""baladia"": """",
""wilaya"": """",
""moufatecheReport"": """"
}'," + teacherId + ");";
我有一些包含变量的逐字字符串,我的问题是我总是从编译器中得到这个错误:
; expected
那我怎么才能正确转义呢?
int teacherId = sqlStatus = (int)sqlCmd.LastInsertedId;
sqlCmd.CommandText = @"INSERT INTO report (report_type, report_date, semester, report_details, teacher_id)
VALUES (0, ""2018-01-01"", 1, '{
""teacherId"": "" " + teacherId.ToString() + " "", <=== error here (; expected)
""mahderDate"": """",
""teacherShool"": """",
""baladia"": """",
""wilaya"": """",
""moufatecheReport"": """"
}'," + teacherId + ");";
使用@poke 的建议,我设法通过在行中放置双引号和@ 使其工作:
int teacherId = sqlStatus = (int)sqlCmd.LastInsertedId;
sqlCmd.CommandText = @"INSERT INTO report (report_type, report_date, semester, report_details, teacher_id)
VALUES (0, ""2018-01-01"", 1, '{
""teacherId"": "" " + teacherId.ToString() + "," +
@" ""mahderDate"": """",
""teacherShool"": """",
""baladia"": """",
""wilaya"": """",
""moufatecheReport"": """"
}'," + teacherId + ");";