Modifying Data in a Table
The DataRow class provides three methods for suspending, reactivating the state of the row while editing. They are,
(1)BeginEdit (2)EndEdit (3)CancelEdit
Eg.,
Dim dr as DataRow = dt.Rows(2) dr.BeginEdit() dr(0)="hi" dr(1)="22" dr.EndEdit()
DataRowVersion It is used when retrieving the value found in a datarow by using Item property.Four types,
(1)Current (2)Default (3)Original (4)Proposed
E.g.,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dr As DataRow
dr = dtTable.Rows(1)
'Represents the Original value lblOriginal.Text = "CTCID is" & dr(0, DataRowVersion.Original) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Original) & "." & "Amount is " & dr(2, DataRowVersion.Original)
'Begin to edit the row dr.BeginEdit()
dr(0) = "2" dr(1) = "4444" dr(2) = "8889"
' Values are changed into 2,4444,8889(Proposed value) lblProposed.Text = "CTCID is" & dr(0, DataRowVersion.Proposed) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Proposed) & "." & "Amount is " & dr(2, DataRowVersion.Proposed)
'Values are not changed, old original values still exists (Current Value) lblCurrent1.Text = "CTCID is" & dr(0, DataRowVersion.Current) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Current) & "." & "Amount is " & dr(2, DataRowVersion.Current)
' Values are changed into 2,4444,8889(Default value) lblDefault.Text = "CTCID is" & dr(0, DataRowVersion.Default) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Default) & "." & "Amount is " & dr(2, DataRowVersion.Default)
'Ending the edition of a row. dr.EndEdit()
'Values are changed into 2,4444,8889(Current value) lblCurrent.Text = "CTCID is" & dr(0, DataRowVersion.Current) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Current) & "." & "Amount is " & dr(2, DataRowVersion.Current)
'Values are not changed, old original values still exists (Original Value) lblOriginal.Text = "CTCID is" & dr(0, DataRowVersion.Original) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Original) & "." & "Amount is " & dr(2, DataRowVersion.Original)
'Make changes into the datatable dtTable.AcceptChanges()
'Now Values are changed, old original values not exists (Original Value) lblOriginal.Text = "CTCID is" & dr(0, DataRowVersion.Original) & "." _ & "Emp_Id is" & dr(1, DataRowVersion.Original) & "." & "Amount is " & dr(2, DataRowVersion.Original)
End Sub
|
No responses found. Be the first to respond and make money from revenue sharing program.
|