views:

51

answers:

3
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.

A: 

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
  • .
rlb.usa
The @ before a string is fine. It allows mulitline string in C# and you don't need to escape spacial characters. Extremly handy for regex and sql queries. i.e.: string pattern = @"\d+"; instead of string pattern = "\\d+";
SchlaWiener
"@" is actually valid where it is; it instructs the string to ignore escape codes. For example, it lets you put "\" in a string instead of forcing you to use the escape code of "\\".
Nate Dudek
Schla beat me to it!
Nate Dudek
+2  A: 

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

thomask
+1  A: 

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].

Serapth
Thank you very much for your help . it is working
Amit Kr. Ghosh