Update Table in Access

  • Thread starter Thread starter PawelR
  • Start date Start date
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
 
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³:
 
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.
 
Back
Top