Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is wrong in this AD0.Net row update?

0 views
Skip to first unread message

Gabriel Langen

unread,
Feb 15, 2004, 3:57:11 PM2/15/04
to
Hi,

Here is a test code! Very simple and short!
The modify of row(0) doen't work but the add.row is OK!!!

I think, all the needed imports are OK!

Thanks
Imports System.Data

Imports System.Data.OleDb


Dim ds_Test As DataSet
Dim da_adapter As OleDbDataAdapter

Dim str_sql As String = "select * from liste_publications order by titre"

Dim str_conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\crisp.mdb"

Dim dr_test As DataRow

ds_Test = New DataSet("DS_Test")

da_adapter = New OleDbDataAdapter(str_sql, str_conn)

Dim SQLBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(da_adapter)

Randomize()

da_adapter.Fill(ds_Test, "Table_1")

' Modify of row(0) : Not OK

ds_Test.Tables("Table_1").Rows(0)("Titre") = " Titre xxxx"

Dim x As String

If ds_Test.HasChanges Then

' Message is OK

msgbox("Changed")

ds_Test.Tables("Table_1").AcceptChanges()

da_adapter.Update(ds_Test, "Table_1")

End If

Dim ajout As Boolean

ajout = True

' add of two rows (OK)

If ajout Then

MsgBox(ds_Test.Tables("Table_1").TableName)

dr_test = ds_Test.Tables("Table_1").NewRow

dr_test("cle") = CStr(Int(Rnd() * 10000))

dr_test("auteur") = "Auteur"

dr_test("titre") = " Titres"

ds_Test.Tables("Table_1").Rows.Add(dr_test)

dr_test = ds_Test.Tables("Table_1").NewRow

dr_test("cle") = CStr(Int(Rnd() * 10000))

dr_test("auteur") = "Auteur"

dr_test("titre") = " Titres"

ds_Test.Tables("Table_1").Rows.Add(dr_test)

da_adapter.Update(ds_Test, "Table_1")

End If

da_adapter.Dispose()

ds_Test.Dispose()

End


Cor

unread,
Feb 16, 2004, 3:15:42 AM2/16/04
to
Hi Gabriel,

When you look in this newsgroup, you will see that a lot of people use the
acceptchanges for someting that it is not made for.

Acceptchanges is for:
to set the dataset that all updates are correct processed.

> ds_Test.Tables("Table_1").AcceptChanges()
> da_adapter.Update(ds_Test, "Table_1")

So with this sentence there is nothing to update anymore,
You only have the acceptchanges row, because the update does (if every thing
is correct) that himself with a full dataset.

I hope this helps?

Cor


Miha Markic [MVP C#]

unread,
Feb 16, 2004, 3:25:24 AM2/16/04
to
HI Gabriel,

Just don't call AcceptChanges *before* Update and everything will be fine :)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Gabriel Langen" <lan...@rspo.ucl.ac.be> wrote in message
news:el2AQKB9...@TK2MSFTNGP11.phx.gbl...

Michael Hampel

unread,
Feb 16, 2004, 4:42:30 AM2/16/04
to
Move the dataset AcceptChanges call to after the data adaptor Update
call.

Calling AcceptChanges of the dateset causes all the rowstate
indicators to be reset so when Update is called it checks the data
tables rowstates and as they are all unmodifed no updates take place.

"Gabriel Langen" <lan...@rspo.ucl.ac.be> wrote in message news:<el2AQKB9...@TK2MSFTNGP11.phx.gbl>...

Gabriel Langen

unread,
Feb 16, 2004, 6:32:04 AM2/16/04
to
Thanks a lot to everybody! When I look to some books it is not clear!


"Cor" <n...@non.com> a écrit dans le message de
news:uGRPqVG9...@tk2msftngp13.phx.gbl...

gh0st54

unread,
Feb 16, 2004, 8:23:22 AM2/16/04
to
Hi

I think your problem is here

> If ds_Test.HasChanges Then
>
> ' Message is OK
>
> msgbox("Changed")
>

> ds_Test.Tables("Table_1").AcceptChanges() <--------- you should not accept changes. see explanation below


>
> da_adapter.Update(ds_Test, "Table_1")
>
> End If


if you accept the changes , the data adapter flags the lines has no
changes.
this means that the data adapter cannot send the changes to the
database, because the row is not marked with changes.

remove that line and it should be fine.

"Gabriel Langen" <lan...@rspo.ucl.ac.be> wrote in message news:<el2AQKB9...@TK2MSFTNGP11.phx.gbl>...

Jay B. Harlow [MVP - Outlook]

unread,
Feb 16, 2004, 9:29:46 AM2/16/04
to
Gabriel,
Have you tried David Sceppa's book "Microsoft ADO.NET - Core Reference" from
MS Press?

I find David's book to be both a good tutorial on ADO.NET plus a good desk
reference once you know ADO.NET!

Hope this helps
Jay


"Gabriel Langen" <lan...@rspo.ucl.ac.be> wrote in message

news:eopQDCI...@tk2msftngp13.phx.gbl...

Gabriel Langen

unread,
Feb 16, 2004, 9:52:19 AM2/16/04
to
Thank you! I will look for it!

"Jay B. Harlow [MVP - Outlook]" <Jay_Har...@msn.com> a écrit dans le
message de news:eaOfZlJ9...@TK2MSFTNGP10.phx.gbl...

0 new messages