hello can somebody check my query cause i'm having a hard time working on it., i need to insert data on my database when i process it tells syntax error in Insert into statement pls. help thnx

try
                {
                    OleDbCommand cmdSave = new OleDbCommand();
                    cmdSave.Connection = cls_DB.cn;
                    cmdSave.CommandText = "insert into tblMember(Std_ID,Last_N,First_N,Mid_N,Level,Section) values (?,?,?,?,?,?)";
                    cmdSave.Transaction = Tran;
                    cmdSave.Parameters.Add("@Std_ID", OleDbType.VarChar).Value = this.txtStud_ID.Text;
                    cmdSave.Parameters.Add("@Last_N", OleDbType.VarChar).Value = this.txtLast_N.Text;
                    cmdSave.Parameters.Add("@First_N", OleDbType.VarChar).Value = this.txtFirst_N.Text;
                    cmdSave.Parameters.Add("@Mid_N", OleDbType.VarChar).Value = this.txtMid_N.Text;
                    cmdSave.Parameters.Add("@Level", OleDbType.VarChar).Value = this.cmbLevel.Text;
                    cmdSave.Parameters.Add("@Section", OleDbType.VarChar).Value = this.txtSection.Text;

                    cmdSave.ExecuteNonQuery();
                    cmdSave.Parameters.Clear();
                    cmdSave.Dispose();
                    Tran.Commit();
                    cls_Function.setMessageBox("Data Edited Successfuly", 1);

                }
                catch (Exception exp)
                {
                    Tran.Rollback();
                    cls_Function.setCreateError(exp.Message);

                }
                finally
                {
                    if (this.cls_DB.cn != null) this.cls_DB.cn.Close();
                }

- Insert statement should be:

cmdSave.CommandText = "insert into tblMember(Std_ID,Last_N,First_N,Mid_N,Level,Section) values (@Std_ID,@Last_N,@First_N,@Mid_N,@Level,@Section)";

- You don't have to write explicity which data type is parameter (in some cases you must - very rare), and when you add parameter to SqlCommand there should be no '@' sign.

cmdSave.Parameters.Add(new SqlParameter("Std_ID", this.txtStud_ID.Text));
cmdSave.Parameters.Add(new SqlParameter("Last_N", this.txtLast_N.Text));
cmdSave.Parameters.Add(new SqlParameter("First_N", this.txtFirst_N.Text));
cmdSave.Parameters.Add(new SqlParameter("Mid_N", this.txtMid_N.Text));
cmdSave.Parameters.Add(new SqlParameter("Level", this.cmbLevel.Text;));
cmdSave.Parameters.Add(new SqlParameter("Section", this.txtSection.Text));

Advice

Use Trim() when inserting data into database.

sir i allready follow your command but another error come up sqlparameter is not required to use in ole command how is it?

I assume you are dealing with Access database, thats why you are trying to use question marks (???) when defining Values(in here), righ?
Correct way, only some part is missing.
You actually have to specifry the column names and not using question marks. Questio marks are only used in Update statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.