I have spent the past couple of days on this. I'm trying to update a row to a access database and I keep getting the error "Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
My Code looks like:
public partial class Form1 : Form
{
OleDbConnection myconnection = new OleDbConnection();
OleDbDataAdapter mydata_adapter = new OleDbDataAdapter();
DataTable Contacts_Table = new DataTable();
int m_rowPosition = 0;
public Form1()
{
InitializeComponent();
myconnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SimpleTest.MDB;Mode=ReadWrite;Persist Security Info=False";
OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(mydata_adapter);
mydata_adapter = new OleDbDataAdapter("Select * From Contacts", myconnection);
mydata_adapter.Fill(Contacts_Table);
DataRow Contacts_Row = Contacts_Table.Rows[0];
Contacts_Row ["Animal"] = "Dinosaur";
this.ShowCurrentRecord();
Contacts_Table.Rows[m_rowPosition]["Animal"] = Animal.Text;
Contacts_Table.Rows[m_rowPosition]["Weight"] = Weight.Text;
mydata_adapter.Update(Contacts_Table);
}
I have read that generally this happens when a primary key isn't set but I I've done that. My update command is
UPDATE `Contacts` SET `Animal` = ?, `Weight` = ? WHERE (((? = 1 AND `ID` IS NULL) OR (`ID` = ?)) AND (`Animal` = ?) AND ((? = 1 AND `Weight` IS NULL) OR (`Weight` = ?)))This is created automatically though so I don't know if its valid.
I've also been told to select the "refresh the data table" option but it is grayed out and I don't think it is supported by access databases. Anywho, I'm freaking out!


Sign In
Create Account


Back to top









