C# - Oledb - Not updating

本文关键字:updating Not Oledb | 更新日期: 2023-09-27 18:05:34

我对Oledb的工作方式不是最好的,但是请您帮帮我。我有一个访问数据库,其中的代码连接到;问题是执行我的CommandText后,没有错误发生,但数据库不更新。

我可能漏掉了什么,请不要生气。

    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();
    }

C# - Oledb - Not updating

你可以试试用这些东西

    string query;
    OleDBlDataAdaptor da;
    OleDBCommandBuilder cb;
    DataSet ds = new DataSet();