INSERT INTO语句中的语法错误

时间:2010-06-17 21:12:58

标签: c# oledbcommand

conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\database.mdb");
conn.Open();

com = new OleDbCommand(@"insert into group
                          (groupid,groupname,nature,effect) 
                         values 
                          (@groupid,@groupname,@nature,@effect)", conn);
com.Parameters.AddWithValue("@groupid", intialtxt);
com.Parameters.AddWithValue("@groupname", groupnametxt);
com.Parameters.AddWithValue("@nature", groupnaturecombo);
com.Parameters.AddWithValue("@effect", efectivegroupcombo);
com.ExecuteNonQuery();

conn.Close()

我已经写了这个连接,但是我在INSERT INTO语句中遇到一个错误语法错误 请有人帮助我。

3 个答案:

答案 0 :(得分:2)

疯狂猜测,但尝试输入[group]而不是group。我假设组字是由于“GROUP BY”子句而保留的。

答案 1 :(得分:1)

Ahhh MS Access带有极其愚蠢的命名容限,允许表名中的空格允许使用SQL关键字作为字段名。

GROUP是SQL reserved word。如果有机会,我强烈建议您重命名。也就是说,如果你不能重命名它,请在查询[group]中用方括号括起来。

答案 2 :(得分:0)

  

OleDbCommand(@“插入组(

你有一些拼写错误:

  • 表格名称和开放式表格之间应该有一个空格,如下所示:group (groupid