Dataset NOT Updating

M

MadCrazyNewbie

Hey Group,

Could sombody possibly have a look at the following code for me please?

It all works fine but when I click on the btnUpdate_Click, after making
changes to the data, it just seems to load the old Dataset again, I checked
mydatabase and no of the changes had taken effect in there?

Im pretty should its something nice and simple I jut carn`t se what:(

Heres the Code:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Me.UpdateDataSet()
Catch eUpdate As System.Exception
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLoad.Click
Try
mlLoading = True
Me.LoadDataSet()
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
Finally
mlLoading = False
End Try
Me.dsArcirisUsers_PositionChanged()
End Sub

Private Sub dsArcirisUsers_PositionChanged()
If Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Position <> -1
Then
Me.cboArcirisUsersPrimarySite.SelectedValue =
dsArcirisUsers.ArcirisUsers.Rows(Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position).Item("SitesID")
End If
Me.lblNavLocation.Text = (((Me.BindingContext(dsArcirisUsers,
"ArcirisUsers").Position + 1).ToString + " of ") +
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").Count.ToString)
End Sub

Public Sub UpdateDataSet()
Dim objArcirisUsersDataSetChanges As Excellence.NET.dsArcirisUsers =
New Excellence.NET.dsArcirisUsers()
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
objArcirisUsersDataSetChanges = CType(dsArcirisUsers.GetChanges,
Excellence.NET.dsArcirisUsers)
If (Not (objArcirisUsersDataSetChanges) Is Nothing) Then
Try
Me.UpdateDataSource(objArcirisUsersDataSetChanges)
dsArcirisUsers.Merge(objArcirisUsersDataSetChanges)
dsArcirisUsers.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If
End Sub

Public Sub LoadDataSet()
Dim objArcirisUsersDataSetTemp As Excellence.NET.dsArcirisUsers
objArcirisUsersDataSetTemp = New Excellence.NET.dsArcirisUsers()
Try
Me.FillDataSet(objArcirisUsersDataSetTemp)
Catch eFillDataSet As System.Exception
Throw eFillDataSet
End Try
Try
dsArcirisUsers.Clear()
dsArcirisUsers.Merge(objArcirisUsersDataSetTemp)
Catch eLoadMerge As System.Exception
Throw eLoadMerge
End Try
End Sub

Public Sub UpdateDataSource(ByVal ChangedRows As dsArcirisUsers)
Try
If (Not (ChangedRows) Is Nothing) Then
Me.odcMainMenu.Open()
odaArcirisUsers.Update(ChangedRows)
odaSites.Update(ChangedRows)
End If
Catch updateException As System.Exception
Throw updateException
Finally
Me.odcMainMenu.Close()
End Try
End Sub

Public Sub FillDataSet(ByVal dataSet As Excellence.NET.dsArcirisUsers)
dataSet.EnforceConstraints = False
Try
Me.odcMainMenu.Open()
Me.odaArcirisUsers.Fill(dataSet)
Me.odaSites.Fill(dataSet)
Catch fillException As System.Exception
Throw fillException
Finally
dataSet.EnforceConstraints = True
Me.odcMainMenu.Close()
End Try
End Sub

Many Thanks
MCN
 
C

Cor

HI Peter,

I did not look at all the code only what got me the first.
If (Not (objArcirisUsersDataSetChanges) Is Nothing) Then
Try

Normaly it is
If datasetX.haschanges then

And why do you not do
Public Sub UpdateDataset(byval ds as dataset)

Cor
 
M

MadCrazyNewbie

Cor,

Sorry im a newbie, what do you mean by do "Public Sub UpdateDataset(byval ds
as dataset)" ?

Thanks
MCN
 
G

Greg

If you are using DataBinding you need to end the current edit. Its also
more efficient to call HasChanges on DataSet. If True, then call GetChanges
and pass only the changes to your Update call.
 
C

Cor

Hi Peter,

I had a long message, but I think it will become a mess when I send it to
you.

Your code looks nice, there are really nice parts in it but also it looks
that you have added and added and never stuffed.

Try to narrow your code down again.

As example from bringing it down can be .
\\\
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Me.UpdateDataSet()
"""This one does nothing generic, so you can for the same place here instead
of that call from the Sub (The code is far to much in my opinion)

Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
If dsArcirisUsers.haschanges Then
Try
odaArcirisUsers.Update(dsArcirisUsers)
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If
///
But this is just a guess, because your code is not that visible for me.

Cor
 
C

Cor

Hi Peter,

There is in the newsgroups no problem sending attachment (if they are
small).

I have looked to it the first one has nothing to do with your problem just
an attention.
Why do you use application.exit instead of me.close ?

Surely you have to change that removeAt, by deleteAt (I do not know how it
is now, but in past that was hardly to find in the documentation). The
removeAt deletes it definitaly and the update will not be done.

Than you try those changes I said with the update and with the fill in the
same trend.

Also what I cannot see is how many tables are you using because this one I
do not understand. I see thas odaSites nowhere back, but maybe you have
binded that to something in the designer.

Me.odcMainMenu.Open()
Me.odaArcirisUsers.Fill(dataSet)
Me.odaSites.Fill(dataSet)

Cor
 
M

MadCrazyNewbie

Cor,

I tryed to send my app by attachment but it dosn`t seem to want to work:(

What do you mean by "Changin that removeAt, by deleteAt".
Also what is the difference between Application.Exit and Me.Close?

Also i`ve changed my code to:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Me.UpdateDataSet()
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
If dsArcirisUsers.haschanges Then
Try
odaArcirisUsers.Update(dsArcirisUsers)
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If

But it still does the same, dosn`t make changes but seems to just load the
dataset again:(

Thanks
MCN

My e-mail is (e-mail address removed) (Removing NOSPAM) incase where
going off topic

Many Thanks Again
MCN
 
C

Cor

Hi Peter,
What do you mean by "Changin that removeAt, by deleteAt".

The removeat is means when you do not an update of your dataset. It removes
the row and does direct the acceptchanges from that row. The delete leaves
the row and set the rowstate to deleted. (Which will be removed by a update
of a complete datasettable or a dataset.acceptchanges)

You have the removeAt in your code and I am almost sure you want there the
deleteAt
Also what is the difference between Application.Exit and Me.Close?
You use Application.Exit, while in the situation you are using it me.close
is more normal in my opinion.
Also i`ve changed my code to:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Me.UpdateDataSet()
That one above was my idea to remove (try it and I am curious if this simple
corrections lets do it work better)
 
M

MadCrazyNewbie

Sorry Cor:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Me.BindingContext(dsArcirisUsers, "ArcirisUsers").EndCurrentEdit()
If dsArcirisUsers.haschanges Then
Try
odaArcirisUsers.Update(dsArcirisUsers)
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If

The above dosn`t work either:(

Thanks
MCN
 
C

Cor

And no errors at all?

By the way are you debugging and can you see if it now goes in that try
block?

Cor
 
M

MadCrazyNewbie

Hey Cor

No Errors sorry - how do i check to see if it goes in the try block?

Ta
MCN
 
C

Cor

Hi Mad,

I hope you see this tomorrow,
You do not know debugging and it is so easy.

Push while the mouse is on that "if haschanges" on the right click from your
mouse.
Choose set breakpoint the row, that row should become brown
and do run.

Then the program stops on that breakpoint.

If you did not change it in the options, than you can with clicking on the
F11 going row by row thru your code.

Should give you a greath help.

Cor
 
M

MadCrazyNewbie

Hey Cor,

Sorry no errors show up anywhere, im so confused, i knew learning VB.Net
would be hard but this is really starting to anoy me now:(

I know it must be something so simple, but i just don`t know what:(

Many thanks
MCN
 
C

Cor

Did you try that debugging with the break, and goes it in that haschanges
part if you do that?
 

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

Similar Threads

Anoying Problem 6
Error clearing Date fields 2
Update problem 1
Really Anoying problem 2
Applying Filter 5
Going Crazy with this! 1
DataRow - How To? 13
Judt a quick Check 2

Top