0

This is the code i wrote but it's not changing any data in the database even after a successful messageBox

 connection.Open();
            command = new OleDbCommand("UPDATE employeeTable SET fullname=@fullname, [gender]=@gender, [dept]=@dept, [sector]=@sector, [sub_sector]=@sub_sector, [timetable]=@timetable WHERE empid=@empid", connection);



            command.Parameters.AddWithValue("@empid", txtEmpID.Text);
            command.Parameters.AddWithValue("@fullname", txtName.Text);
            command.Parameters.AddWithValue("@gender", cboGender.SelectedItem.ToString());
            command.Parameters.AddWithValue("@dept", cboCompany.SelectedItem.ToString());
            command.Parameters.AddWithValue("@sector", cboSector.SelectedItem.ToString());
            command.Parameters.AddWithValue("@sub_sector", cboSub.SelectedItem.ToString());
            command.Parameters.AddWithValue("@timetable", cboTimetable.SelectedItem.ToString());
            command.ExecuteNonQuery();
            connection.Close();
            MessageBox.Show("Record Updated Successfully!", "NEW EMPLOYEE ADDED", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
2
  • is @empid in datatable? update didn't add new records to table Commented Mar 24, 2022 at 7:38
  • the empid is the employment id each user had during the creating of new user. So each employee has different ID. So i thought using it to Select the table thats why. But irrespective of the update and it saved successfully, IT WONT UPDATE IN THE DATABASE Commented Mar 24, 2022 at 8:18

2 Answers 2

1

The arrangement of parameters in your OleDbCommand and Parameters must be the same

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

Comments

0

I didn't get to run your code so you might want to try using

 command.ExecuteScalar();

instead of

command.ExecuteNonQuery();

Also try to avoid direct use of SQL Reserve words for your database table Fields like LEVEL etc so that you avoid SQL Errors.

4 Comments

Okay thank you so much, I'd work on it
you are welcome. It was around 2006 that i discovered some of the keywords i was using in queries were making the sql queries to fail in Visual Basic 6.0. Since then words like Session, Level, etc are SQL Admin management keywords and when used in queries returns errors or may not work as expected and so are not used in my project exactly as they are. My suggestion is if you are designing a school managment app, you might be using things like stdsession for student session, stdlevel for student Level etc...
Im working on an employee software in keeping records of the tools and the one collected
Just make your fields like empname for employee name and so on...

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.