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
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
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...
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>...
"Cor" <n...@non.com> a écrit dans le message de
news:uGRPqVG9...@tk2msftngp13.phx.gbl...
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>...
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...
"Jay B. Harlow [MVP - Outlook]" <Jay_Har...@msn.com> a écrit dans le
message de news:eaOfZlJ9...@TK2MSFTNGP10.phx.gbl...