简体   繁体   中英

Syntax error in INSERT INTO statement

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()

i have write this connection ,but i get one error Syntax error in INSERT INTO statement please someone help me.

Wild guess, but try to type [group] instead of just group. I assume the group word is reserved because of the "GROUP BY" clause.

Ahhh MS Access with your exceedingly stupid naming allowances, from allowing spaces in table names to permitting use of SQL keywords for field names.

GROUP is a SQL reserved word . If you have the chance, I highly recommend you rename it. That said, if you can't rename it, surround it with square brackets in the query [group].

OleDbCommand(@"insert into group(

You have some typos:

  • there should be a space between the table name and your open paren, like this : group (groupid
  • .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM