mariusgherman
mariusgherman

Reputation: 29

Updating DataTable

for(int i = 0; i < m_DataTable.Rows.Count; i++)
{
    m_DataTable.Rows[i]["WORKER"] = "test";
    m_DataTable.Rows[i].AcceptChanges();
}

m_DataTable.AcceptChanges();

Is there any reason that I can not see that this code does not update my dataTable?

Upvotes: 0

Views: 1468

Answers (1)

Stephen Chung
Stephen Chung

Reputation: 14605

Shouldn't you be creating a data adaptor and call Update to update the dataset changes to your database, before you call AcceptChanges?

Something like:

using (DataAdaptor adaptor = new DataAdaptor("SELECT * FROM table", connection)) {
    using (CommandBuilder builder = new CommandBuilder(adaptor)) {
        adaptor.Update(m_DataTable);
    }
}

m_DataTable.AcceptChanges();

Upvotes: 3

Related Questions