Update Table in Access

P

PawelR

Hello Group,
In my apps I fill DataSet from MSAcces (file db1.mdb)
oleDbDataAdapter1.Fill(fromAccessDS,"MyTable")
MyTable heve 4 columns,
I change in dataGrid
(dataGrid.DataSource=fromAccessDS.Tables["MyTable"]) value in this
table.
My question:
How update Table in file db1.mdb), save my change in this table?

Thx
PawelR
 
P

PawelR

Hi Nicholas,
I use oleDbDataAdapter1.Update(fromAccesDS) and
oleDbDataAdapter1.Update(fromAccesDS.MyTable) and
oleDbDataAdapter1.Update(fromAccesDS.Tables["MyTable"])

and file db1.mdb is not changes.

Meybe I don't understend You. My English is very poor. Please write me
example lines.

Thx
Pawel


Nicholas Paldino [.NET/C# MVP] napisa³:
 
C

Carl Fenley

In this example, I'm using a connection object named 'master'.

string strSelectA = "SELECT * FROM REF_CSDTransition";
OleDbDataAdapter refAdapter = new OleDbDataAdapter(strSelectA, master);
OleDbCommandBuilder refCommand = new OleDbCommandBuilder(refAdapter);

// The OleDbCommandBuilder will automatically generate the Insert command
for the Update method...

try
{
refAdapter.Fill(ds1, "ref");
}
finally
{
master.Close();
}

// Change your dataset table "ref" here!

try
{
master.Open();
refAdapter.Update(ds1, "ref");
}
finally
{
master.Close();
ds1.Tables["ref"].Dispose();
}

Disposing the "ref" dataset table is not necessary, but I did in this
instance since I am no longer using it at this point.

Good Luck

- carl


PawelR said:
Hi Nicholas,
I use oleDbDataAdapter1.Update(fromAccesDS) and
oleDbDataAdapter1.Update(fromAccesDS.MyTable) and
oleDbDataAdapter1.Update(fromAccesDS.Tables["MyTable"])

and file db1.mdb is not changes.

Meybe I don't understend You. My English is very poor. Please write me
example lines.

Thx
Pawel


Nicholas Paldino [.NET/C# MVP] napisa³:
Pawel,

If you still have the DataAdapter which you used to get the data, then
you can set the Update, Delete and Insert command properties to commands
that should be executed to update the rows in the table. You then call
Update, passing the dataset with the modified data to the method.

Hope this helps.
 

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

Similar Threads

slow fill 1
Remove Row in table 1
Format String 2
Fill treeView from DataTable 2
Sort in dataSet 1
Delete row 1
Show data in from DataSet in TextBox 4
How to force DataAdapter NOT to update added rows? 1

Top