Data Adapter update

B

!!bogus

Hi,

This is partial code. I am trying to update the table, but it is not working
and I am not sure why. Can you please help? I don't get any errors, but the
table is not updated. I am sure I am missing something

Thank you

Dim cnNewMember As SqlConnection = New
SqlConnection(Constants.ConnectionString)
Dim dsNewMember As New DataSet("NewMember")

Try
Dim daNewMember As New SqlDataAdapter( _
"SELECT * FROM tree_members", cnNewMember)
cnNewMember.Open()

daNewMember.Fill(dsNewMember)


Dim strAName As String = Response.Cookies("aname").Value
Dim strANickName As String = Response.Cookies("anickname").Value
Dim strFatherID As Integer =
CInt(Response.Cookies("fatherid").Value)
Dim strMotherID As Integer =
CInt(Response.Cookies("motherid").Value)

Dim drNewMember As DataRow

drNewMember = dsNewMember.Tables(0).NewRow
drNewMember.Item("aname") = strAName
drNewMember.Item("anickname") = strANickName
drNewMember.Item("fatherid") = strFatherID
drNewMember.Item("motherid") = strMotherID
dsNewMember.Tables(0).Rows.Add(drNewMember)

If dsNewMember.HasChanges Then
dsNewMember.AcceptChanges()
dsNewMember.Tables(0).AcceptChanges()
'Response.Write(dsNewMember.Tables(0).Rows.Item(1))
daNewMember.Update(dsNewMember.Tables(0))
End If

Catch
.....
.....
 
J

Joseph Byrns

Where you have:

If dsNewMember.HasChanges Then
dsNewMember.AcceptChanges()
dsNewMember.Tables(0).AcceptChanges()
'Response.Write(dsNewMember.Tables(0).Rows.Item(1))
daNewMember.Update(dsNewMember.Tables(0))
End If

you are AcceptingChanges before you update, and so telling it there are no
changes. What you should do is something like:

If dsNewMember.HasChanges Then
dim dtChanges as datatable =
dsNewMember.Tables(0).GetChanges()

daNewMember.Update(dtChanges)

dsNewMember.AcceptChanges()
dsNewMember.Tables(0).AcceptChanges()
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top