I am not the best with how Oledb works, but please can you help me out. I have an access database in which the code is connected to; the problem is after executing my CommandText, no errors occur but the database does not update.
I might have missed something, please don't be annoyed.
private void parametersEditCreate() // Used within method below
{
dateTime = Convert.ToDateTime(dtpDateofBirth.Value.ToShortDateString());
command.Parameters.AddWithValue("@forename", txtForename.Text);
command.Parameters.AddWithValue("@surname", txtSurname.Text);
command.Parameters.AddWithValue("@username", txtUsername.Text);
command.Parameters.AddWithValue("@password", txtPassword.Text);
command.Parameters.AddWithValue("@class", txtClass.Text);
command.Parameters.AddWithValue("@dob", dateTime.ToString());
command.Parameters.AddWithValue("@gender", txtGender.Text);
command.Parameters.AddWithValue("@cf", txtCourseFavourite.Text);
}
private void createEditRecord(string ID) // If 'Edit' disable StudentID (Autoincrement) and ignore (string ID) parameter, otherwise update.
{
string query;
connection.Open();
if (Teacher.CreateOREdit == "Edit")
{
query = "UPDATE tblStudent SET [Forename]=@forename,[Surname]=@surname,[Username]=@username,[Password]=@password,[Class]=@class,[DateofBirth]=@dob,[Gender]=@gender,[Course Favourite]=@cf WHERE [StudentID]=@id";
command = new OleDbCommand(query, connection);
command.Parameters.AddWithValue("@id", txtStudentID.Text);
parametersEditCreate();
}
else //Create - FOR STACKOVERFLOW, ignore else
{
query = "INSERT INTO tblStudent([Forename],[Surname],[Username],[Password],[Class],[DateofBirth],[Gender],[Course Favourite]) VALUES (@forename,@surname,@username,@password,@class,@dob,@gender,@cf)";
command = new OleDbCommand(query, connection);
}
command.ExecuteNonQuery();
connection.Close();
}