尝试向我的SQLCe db插入数据时,我收到以下错误。
解析查询时出错。 [令牌行号= 1,令牌行偏移= 195,令牌错误= AS]
Heire是我的代码。
_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] 我哪里错了。
答案 0 :(得分:1)
一切都看错了。
但是,您的问题可能是您的字符串中缺少空格,特别是在FROM和INNER JOIN之后以及WHERE之前。查看结果字符串,而不是您的代码。
"...b.End_timeFROM..."
"...INNER JOINSolve_Student_question..."
"...b.sectionnameWHERE..."
答案 1 :(得分:1)
尝试使用此命令文本,我添加了空格。
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 + "')";