[英]C# - Oledb - Not updating
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();
}
您可以嘗試使用這些東西
string query;
OleDBlDataAdaptor da;
OleDBCommandBuilder cb;
DataSet ds = new DataSet();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.