访问 2003 与 2010 c#
我看不出我哪里出错了。没有错误,但没有数据正在更新。我有插入、删除和编辑工作,但我不知道为什么我不能让它工作。请有人在这里帮助我,在此先感谢...
连接字符串
myCon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:..\TempDB.mdb");
更新方法...
private void btnUpdate_Click(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE [Family] SET [FirstName] = ?, [LastName] = ?, [FamilyDOB] = ?, [Medical] = ? WHERE [ID] = ?";
//tried this as well
//cmd.CommandText = "UPDATE [Family] SET [FirstName] = FirstName, [LastName] = @LastName, [DOB] = @StudentDOB, [Medical] = @Medical WHERE [ID] = @ID";
cmd.Parameters.AddWithValue("@ID", txtFamID.Text);
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
cmd.Parameters.AddWithValue("@FamDOB", txtFamDOB.Text);
cmd.Parameters.AddWithValue("@Medical", txtMedical.Text);
cmd.Connection = myCon;
myCon.Open();
cmd.ExecuteNonQuery();
myCon.Close();
}