Solved

Update Issue:  Has to be somthing simple

Posted on 2006-11-17
16
189 Views
Last Modified: 2010-04-23
I have used the code below multiple times in other applications.  The update method below covers all changes to the dataset no matter how many things you change, except for "$1.00" currency amounts.  The problem I am running into is that will only update the last or most current change.  An example of this would be that I have 3 records, I say something like

Record 1:  $1.00
Record 2:  $2.00
Record 3:  $3.00

Then maybe the user would think, I need to save and presses the save button (update method is fired up.)

The results if you would exit the program and come back in (or just reload the dataset) would be.

Record 1:  $0.00
Record 2:  $0.00
Record 3:  $3.00

If I would press save (update) on each change the data would be updated.

Here's the code I am using to update.

Public Sub UpdateDataset()
        Try

            BSYear.EndEdit()
            BsTenant.EndEdit()
            BsMonth.EndEdit()
            BsHistory.EndEdit()

            adYear.Update(Me.DsetMLPRentals.MLPYear)
            adTenant.Update(Me.DsetMLPRentals.MLPTenant)
            adMonth.Update(Me.DsetMLPRentals.MLPMonths)
            adHistory.Update(Me.DsetMLPRentals.MLPHistory)

            DsetMLPRentals.GetChanges()
            DsetMLPRentals.AcceptChanges()

        Catch EUpdate As System.Exception
            MessageBox.Show(EUpdate.Message)
            System.Windows.Forms.MessageBox.Show(EUpdate.Message)
        End Try
    End Sub

Thanks for all the help,

Ryan
0
Comment
Question by:rhutzel
  • 8
  • 8
16 Comments
 
LVL 14

Expert Comment

by:jake072
Comment Utility
I think that your problem is not due to your update, but rather some other validation or event that you are firing when a user changes the cells or something.

Do you have any validation of the input?

Jake
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
Jake,

Here is the only event that is running with the input of the textboxes other than the databindings.

Private Sub txtJan_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtJan.KeyPress, TxtFeb.KeyPress, _
    txtMar.KeyPress, txtApr.KeyPress, txtMay.KeyPress, txtJune.KeyPress, txtJuly.KeyPress, txtAug.KeyPress, txtSept.KeyPress, txtOct.KeyPress, txtNov.KeyPress, TxtDec.KeyPress

        Select Case e.KeyChar.ToString
            Case vbBack : Exit Sub ' Backspace
            Case "0" To "9" : Exit Sub ' Numbers
            Case "." : Exit Sub 'Period

        End Select

        Beep()
        e.Handled = True
    End Sub

It is just to keep users from typing in anything else other than numerical keys.

Thanks,

Ryan
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
Well it seems that this problem is a little more complicated than I thought or the points are not high enough....sooooo, I raised them.  I hope somebody can help:)

Thanks,

Ryan
0
 
LVL 14

Expert Comment

by:jake072
Comment Utility
Ryan,


I'm not sure that I understand what your problem is.  The validation code above is for the textbox, and should not affect your data.  The problem as I see it is that it's not updating all the changed records, is that correct?  If so, I might suggest removing all your end edit commands.  I'm not sure what you have them there for, but they can cause problems if not used correctly.

Let me know,

Jake
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
Jake,

The problem is that with the code that I explained before, only the current record gets updated back to the server (SQL).
I attempted to remove all the *.endedit's and upon doing that now nothing changes.

Again I have used this method for saving (updating) in the rest of the application.

Simple answer is that the update is only saving the last record changed.  You could change fifty records before it and the only one that will save is the last record.

Thanks,

Ryan
0
 
LVL 14

Expert Comment

by:jake072
Comment Utility
How are you modifying the records?

Jake
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
They are being modified via textboxes on a form.  Each record is selected from a datagridview.  

Ryan
0
 
LVL 14

Expert Comment

by:jake072
Comment Utility
Ryan,

So you pick a record, modify it via a form that get's opened, then you close the form, pick another record, modify it, etc. etc., then you update from the main form holding the datagridview?

If this is the case, then I'd like to see the code for that form (exclude windows designer code)...

With that, I can see how your passing information, etc., to see if there is something I can find...

Jake
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:rhutzel
Comment Utility
A user clicks on the datagrid view client record.
The clients information shows up in the textboxes below.
When the user is done editing, they would press a save button. (Fires up the update method described earlier)
The user moves onto another record and so on.

The problem again is that you can save one record at a time, but if you make changes to a record and move to another and make changes, the last record will not save when the save button is pressed.

I hope this clears things up a little,

Ryan
0
 
LVL 14

Expert Comment

by:jake072
Comment Utility
what happens when you switch between records, is there any code?

Jake
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
Everything is databinded.

I am not sure what you mean.

Ryan
0
 
LVL 14

Expert Comment

by:jake072
Comment Utility
I would call an accept changes before you let the datagrid switch positions, see if that works.

Jake
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
What event would you place a "dataset.Acceptchanges()" in?

Thanks,

Ryan
0
 
LVL 14

Accepted Solution

by:
jake072 earned 250 total points
Comment Utility
Try the row validating event.

I would put a breakpoint in here too, so that you can see what the data is in the datarow.  If you notice that it isn't retaining the new value after you call acceptchanges, then we'll have to try something else.  I've run into this a few years ago, I'm just trying to remember what it was, I'm pretty sure it had to do with endcurrentedit.  You might try adding endcurrentedit for the row rather than acceptchanges.

Let me know,

Jake
0
 
LVL 1

Author Comment

by:rhutzel
Comment Utility
Jake,

Just to let you know that placing the *.endedit's into the row validating event worked like a charm.  I don't really  understand why this application is so much different than the other apps that I have created, but you the man:)

Thanks,
0
 
LVL 14

Expert Comment

by:jake072
Comment Utility
Ryan,

Glad to know that solved it for you.  I knew I'd run across this issue before, glad to help.

Jake
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now