OleDbDataAdapter, Fill, Update, CommandBuilder and PrimaryKeys  
Author Message
Maartin





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter, Fill, Update, CommandBuilder and PrimaryKeys Top

Hi again,
I used to change my database-tables using an OleDbDataAdapter, filling a DataTable with the table-data, change it and call Update again to save the changes. This was easily possible with the help of a CommandBuilder.
No I've got the problem that a table has no primarykey and i can't define it because there are no (not even mutliple-column) unique entries.

    m_dbAdptrRemedies = new OleDbDataAdapter("","Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_RemediesFilename);
    m_dbAdptrRemedies.SelectCommand.CommandText ="SELECT * FROM tMittelListe";
    new OleDbCommandBuilder(m_dbAdptrRemedies);

So how do i update my changes in the DataTable to the database



.NET Development16  
 
 
Paul Domag





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter, Fill, Update, CommandBuilder and PrimaryKeys Top

Hi,

If you don't have a primary key then you must manually specify the Update Statemen to execute when the datatable is updating. Just use the adapter.UpdateCommand to achieve this.

m_dbAdptrRemedies.UpdateCommand = new OleDbCommand("your update statement", <connection object>)

Just do the same thing with the DeleteCommand, InsertCommand

cheers,

Paul June A. Domag



 
 
Maartin





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter, Fill, Update, CommandBuilder and PrimaryKeys Top

Hi,
is there anywhere a sample or better explanation for this process
I already tried to fill these Commands before calling Update, but it didn't work.

 
 
Maartin





PostPosted: .NET Framework Data Access and Storage, OleDbDataAdapter, Fill, Update, CommandBuilder and PrimaryKeys Top

Ah, I found the article "Updating Data Sources with DataAdapters" in the .NET Framework Developer's Guide. This helped.