Link to home
Start Free TrialLog in
Avatar of adwooley2
adwooley2

asked on

Datagridview - updating problems

Have a datagridview hooked up to a dataset on the fly.
The datagridview cells can be individually editted or rows can be selected and editted in bulk fashion.
The bulk edit looks like this:
          For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows
                row.Cells(5).Value = IIf(Me.txtTop.Text = "", 0, Me.txtTop.Text)
                row.Cells(6).Value = IIf(Me.txtBottom.Text = "", 0, Me.txtBottom.Text)
                row.Cells(7).Value = IIf(Me.txtLeft.Text = "", 0, Me.txtLeft.Text)
                row.Cells(8).Value = IIf(Me.txtRight.Text = "", 0, Me.txtRight.Text)
            Next

I then want to traverse each row, see if there was a change that was made and then update the database accordingly.

Have a button that fires this:
Dim tbl As DataTable = ds.Tables(0)
        Try
            For Each row As DataRow In tbl.GetChanges.Rows

                db.CropMasterUpdate(IIf(IsDBNull(row.Item(0)), "", row.Item(0)), _
                                    IIf(IsDBNull(row.Item(1)), "", row.Item(1)), _
                                    IIf(IsDBNull(row.Item(2)), "", row.Item(2)), _
                                    IIf(IsDBNull(row.Item(3)), "", row.Item(3)), _
                                    IIf(IsDBNull(row.Item(4)), "", row.Item(4)), _
                                    IIf(IsDBNull(row.Item(5)), 0, row.Item(5)), _
                                    IIf(IsDBNull(row.Item(6)), 0, row.Item(6)), _
                                    IIf(IsDBNull(row.Item(7)), 0, row.Item(7)), _
                                    IIf(IsDBNull(row.Item(8)), 0, row.Item(8)))
            Next
        Catch ex As Exception

        End Try

For some reason, this doesn't pick up the changes done in the last row selected.  Is it because the last row selected is the current row?  Any way to get around this so that even the current row is updated along with the other rows?
SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adwooley2
adwooley2

ASKER

I was hopeful that was it, but it didn't work.  Any other ideas?
did you try

datagridview.update method?
I'll try this out after I get home (I'm working in Japan, so the night is young).
See you again.

really:),  me too working in Japan


no jangyou?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sancler,
EndCurrentEdit did the magic.  Thank you very much!

ADWooley