How I can escape a double quote in a verbatim string that contains variables

67 Views Asked by At

I have verbatim string that have some variables contacanete with, my problem I always get this error from the compiler:

; expected

So how I can escape it properly?

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 + ");";
1

There are 1 best solutions below

1
On BEST ANSWER

Using @poke suggestion I managed to get it work with placing a double quote and @ in the line:

    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 + ");";