Re: Trouble updating access database with dataset by Samuel
Samuel
Wed Jul 07 20:23:39 CDT 2004
emde,
When you create the new data adapter, the select statement of the adapter is
automatically created for you.
To update the database you need to create the Insert, Update and Delete
commands of the data adapter.
The easiest way to do this is with the command builder object.
In VB I would add the following code after you declare the new data adpater:
<code (VB.NET) >
Dim dataCommandBuilder As New OleDb.OleDbCommandBuilder(da)
da.InsertCommand = dataCommandBuilder.GetInsertCommand
da.DeleteCommand = dataCommandBuilder.GetDeleteCommand
da.UpdateCommand = dataCommandBuilder.GetUpdateCommand
</code>
Then calling Update on the dataadapter should work.
I would also not use a full dataset, I would use a datatable instead. The
Dataset will contain many tables and relations and could cause an ambiguous
situation.
-Sam Matzen
"emde" <emde@na.com> wrote in message
news:uFs9F2HZEHA.3664@TK2MSFTNGP12.phx.gbl...
>
> Here is my code. It should be updating the first field in the first record
> of the table. No errors occur when I run this but no data is updated
either.
> Any ideas?
>
> Thanks.
>
>
> System.Data.OleDb.OleDbConnection conn = new
> System.Data.OleDb.OleDbConnection();
> conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
> @"Password=pass;User ID=username;" +
> @"Jet OLEDB:System database=q:\system.mdw;" +
> @"Data source=q:\db.mdb";
>
> conn.Open();
>
> string query = "select * from table1";
>
> OleDbDataAdapter da = new OleDbDataAdapter( query, conn );
>
> DataSet ds = new DataSet();
>
> da.Fill( ds );
>
> ds.Tables[0].Rows[0].ItemArray[0] = "newvalue";
>
> da.Update( ds );
>
>
>
>
>
>
>
>
>