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

0

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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

2 Comments

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+";
"@" 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 "\\".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.