problem with OleDb

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
K

Kostya Ergin

Hi Nicholas!

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

Amusing C# :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top