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.SelectedR ows
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(Is DBNull(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?
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.SelectedR
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(Is
IIf(IsDBNull(row.Item(1)),
IIf(IsDBNull(row.Item(2)),
IIf(IsDBNull(row.Item(3)),
IIf(IsDBNull(row.Item(4)),
IIf(IsDBNull(row.Item(5)),
IIf(IsDBNull(row.Item(6)),
IIf(IsDBNull(row.Item(7)),
IIf(IsDBNull(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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did you try
datagridview.update method?
datagridview.update method?
ASKER
I'll try this out after I get home (I'm working in Japan, so the night is young).
See you again.
See you again.
really:), me too working in Japan
no jangyou?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sancler,
EndCurrentEdit did the magic. Thank you very much!
ADWooley
EndCurrentEdit did the magic. Thank you very much!
ADWooley
ASKER