解析查询出错.[令牌行号= 1,令牌行偏移量= 195,令牌错误= AS]

本文关键字:令牌 偏移量 AS 错误 查询 出错 | 更新日期: 2023-09-27 17:51:08

当试图插入数据到我的SQLCe数据库时,我得到以下错误:

解析查询出错。[令牌行号= 1,令牌行偏移量= 195,令牌错误= AS]

这是我的代码。

 _connection.Open();
        cmd.Connection = _connection;
        cmd.CommandText = "INSERT INTO result"+
                     "(Section_name, Qno, Answ, Exame_id, User_id, Start_time, End_time)"+
                    "SELECT  b.sectionname, b.Qno, b.Answ, b.Exame_id AS Expr1, b.User_id, b.Start_time, b.End_time"+
                    "FROM   Question AS a INNER JOIN"+
                     "Solve_Student_question AS b ON a.SubQno = b.Qno AND a.Section_name = b.sectionname"+
                    "WHERE  (b.User_id = '" + userid + "')";
        cmd.CommandType = CommandType.Text;
        try
        {
            cmd.ExecuteNonQuery();

            _connection.Close();
        }
        catch (Exception ee) { }
        _connection.Close();

它将在cmd.ExecuteNonQuery()中给出错误行;错误的刑期解析查询出错。[令牌行数= 1,令牌行偏移量= 195,令牌错误= AS]

解析查询出错.[令牌行号= 1,令牌行偏移量= 195,令牌错误= AS]

试试这个命令文本,我已经添加了空格。

cmd.CommandText = "INSERT INTO result" +
                     "(Section_name, Qno, Answ, Exame_id, User_id, Start_time, End_time)" +
                    " SELECT  b.sectionname, b.Qno, b.Answ, b.Exame_id AS Expr1, b.User_id, b.Start_time, b.End_time " +
                    "FROM   Question AS a INNER JOIN " +
                     "Solve_Student_question AS b ON a.SubQno = b.Qno AND a.Section_name = b.sectionname " +
                    "WHERE  (b.User_id = '" + userid + "')"; 

一切看起来都不对。

  1. 手工编写数据库代码2014?有自动数据层。
  2. 在字符串中构建sql,打开可能的sql注入?使用sql参数
  3. 吞下所有异常,无论如何?你怎么知道什么时候失败了?
然而,您的问题可能是您的字符串中缺少空格,特别是在FROM和INNER JOIN之后以及WHERE之前。查看生成的字符串,而不是您的代码。
"...b.End_timeFROM..."
"...INNER JOINSolve_Student_question..."
"...b.sectionnameWHERE..."