-2

我有逐字字符串,其中包含一些变量,我的问题总是从编译器得到这个错误:

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

1 回答 1

0

使用@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 + ");";
于 2018-01-01T17:42:41.187 回答