Home All Groups Group Topic Archive Search About

Changes not getting saved to data source

Author
23 Apr 2010 4:36 PM
rarahim
Hi. I'm kinda new with ADO .NET. I'm having trouble saving edit and delete
changes back to the data source. Adding new record is fine. Only edits and
deletes don't work.

Here's my code:

        Dim r As DataSet1.PeopleRow

        OleDbDataAdapter1.Fill(DataSet11)

        r = DataSet11.People.Rows(0)

        r.Name = "Kevin"

        r.AcceptChanges()

        Dim ret As Integer = OleDbDataAdapter1.Update(DataSet11)

My DataAdapter and Dataset are strongly typed and they were created through
VS 2008 data wizard. By the way, I'm using an MS Access 2003 database with a
table called People.

People
        Id : Number, primary key
        Name: String

Please help as I'm really stuck. Thanks



--- news://freenews.netfront.net/ - complaints: n***@netfront.net ---

Author
25 Apr 2010 2:09 PM
Armin Zingler
Am 23.04.2010 18:36, schrieb rarahim:
Show quoteHide quote
> Hi. I'm kinda new with ADO .NET. I'm having trouble saving edit and delete
> changes back to the data source. Adding new record is fine. Only edits and
> deletes don't work.
>
> Here's my code:
>
>         Dim r As DataSet1.PeopleRow
>
>         OleDbDataAdapter1.Fill(DataSet11)
>
>         r = DataSet11.People.Rows(0)
>
>         r.Name = "Kevin"
>
>         r.AcceptChanges()
>
>         Dim ret As Integer = OleDbDataAdapter1.Update(DataSet11)
>
> My DataAdapter and Dataset are strongly typed and they were created through
> VS 2008 data wizard. By the way, I'm using an MS Access 2003 database with a
> table called People.

Remove r.AcceptChanges(). The Update methods looks for records with row
state modified, added and deleted. If you call AcceptChanges before,
deleted records have been removed from the datatable, and the row state
of the remaining rows is unchanged. Consequently the update method
doesn#t find anything to do.

--
Armin