Solved

Update Issue:  Has to be somthing simple

Posted on 2006-11-17
16
191 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
ID: 17967053
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
ID: 17967244
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
ID: 18021923
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:jake072
ID: 18028751
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
ID: 18028862
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
ID: 18029025
How are you modifying the records?

Jake
0
 
LVL 1

Author Comment

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

Ryan
0
 
LVL 14

Expert Comment

by:jake072
ID: 18029118
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
 
LVL 1

Author Comment

by:rhutzel
ID: 18029160
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
ID: 18029704
what happens when you switch between records, is there any code?

Jake
0
 
LVL 1

Author Comment

by:rhutzel
ID: 18029755
Everything is databinded.

I am not sure what you mean.

Ryan
0
 
LVL 14

Expert Comment

by:jake072
ID: 18029846
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
ID: 18029944
What event would you place a "dataset.Acceptchanges()" in?

Thanks,

Ryan
0
 
LVL 14

Accepted Solution

by:
jake072 earned 250 total points
ID: 18030106
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
ID: 18030382
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
ID: 18030646
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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