SQL Insert语句不起作用C#

时间:2015-10-20 09:13:42

标签: c# ms-access

使用像这样的Access数据库:

SELECT pt.regno, pt.rfid, MAX(vrt), MAX(fot), MAX(rit), MAX(MI), MAX(wi), MAX(Mo), MAX(wo) FROM (
SELECT *
 FROM (
  SELECT * from @temtable2 t
 ) SourceTable
 PIVOT
(
max(timec)
FOR eventb
IN('Veh Reg Time' AS vrt,'Ftness Ok time' AS fot, 'RFID Issue time' AS rit, 'MG-IN' AS mi, 'WB IN' AS wi, 'MG-OUT' AS mo, 'WB OUT' AS wo)
) PivotTableAlias) pt
GROUP BY  pt.regno, pt.rfid

我试过了:

  1. 取出int i bit。
  2. 将@符号放在语句前面。
  3. 检查并确保我使用的是访问代码。
  4. 尝试在创建之前关闭连接,以防它出现在那里。
  5. 将数据替换为固定值,然后我在Access中的查询中运行。
  6. 将上述访问查询放入代码块 (cmd.CommandText =“INSERT INTO用户(用户名,密码,电子邮件,地址,问题,答案)值('asdasd','Asd! 23asd','asdasd','asdasd','asdasd','asdasd')“; 并尝试运行它并再次出现相同的语法错误。
  7. 请有人帮助我......

3 个答案:

答案 0 :(得分:2)

密码是保留关键字

  cmd.CommandText = "INSERT INTO Users (Username, Password, Email, Address...

试试这个

cmd.CommandText = "INSERT INTO Users (Username, [Password], Email, Address...

答案 1 :(得分:0)

你能试试吗?

 "INSERT INTO Users (Username, Password, Email, Address, Question, Answer) 
    VALUES(
    '" + txtUsernameRP.Text + "',
    '" + txtPasswordRP.Text + "',
    '" + txtEmailRP.Text + "',
    '" + txtAddressRP.Text + "',
    '" + txtQuestionRP.Text + "',
    '" + txtAnswerRP.Text + "');";

答案 2 :(得分:0)

我猜您的问题出在int i上,请尝试将其删除