problem with OleDb

  • Thread starter Thread starter Kostya Ergin
  • Start date Start date
K

Kostya Ergin

Hi,

OleDbConnection m_cnADONewConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
DataTable m_dtBackups = new DataTable();

// Connect:

string path = Application.StartupPath + @"\";
m_cnADONewConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "backup.mdb";
m_daDataAdapter =
new OleDbDataAdapter("Select * From backups",m_cnADONewConnection);
OleDbCommandBuilder m_cbCommandBuilder = new
OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtBackups);

// trying to update:

for (int i=0; i < m_dtBackups.Rows.Count; i++)
{
m_dtBackups.Rows["name"]= "test!";



// Problem here:
m_daDataAdapter.Update(m_dtBackups);



}

How correctly to update?
 
Kostya,

You don't have to pass the table to the data adapter for each row.
Rather, in the table, you make your changes, and call Update once. The
Update method will cycle through the rows in the table that have changes in
them, and then make the appropriate changes.

Hope this helps.
 
Hi Nicholas!

Thanks for tip. I found solution - database need field with primary key.

Amusing C# :)
 
Back
Top