本文整理匯總了VB.NET中System.Data.DataRow.BeginEdit方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataRow.BeginEdit方法的具體用法?VB.NET DataRow.BeginEdit怎麽用?VB.NET DataRow.BeginEdit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataRow
的用法示例。
在下文中一共展示了DataRow.BeginEdit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: DemonstrateRowBeginEdit
Private Sub DemonstrateRowBeginEdit()
Dim table As New DataTable("table1")
Dim column As New DataColumn("col1", Type.GetType("System.Int32"))
AddHandler table.RowChanged, AddressOf Row_Changed
table.Columns.Add(column)
' Add a UniqueConstraint to the table.
table.Constraints.Add(New UniqueConstraint(column))
' Add five rows.
Dim newRow As DataRow
Dim i As Integer
For i = 0 To 4
' RowChanged event will occur for every addition.
newRow = table.NewRow()
newRow(0) = i
table.Rows.Add(newRow)
Next i
' AcceptChanges.
table.AcceptChanges()
' Invoke BeginEdit on each.
Console.WriteLine(ControlChars.Cr _
& " Begin Edit and print original and proposed values " _
& ControlChars.Cr)
Dim row As DataRow
For Each row In table.Rows
row.BeginEdit()
row(0) = CInt(row(0)) & 10
Console.Write(ControlChars.Tab & " Original " & ControlChars.Tab _
& row(0, DataRowVersion.Original).ToString())
Console.Write(ControlChars.Tab & " Proposed " & ControlChars.Tab _
& row(0, DataRowVersion.Proposed).ToString() & ControlChars.Cr)
Next row
Console.WriteLine(ControlChars.Cr)
' Accept changes
table.AcceptChanges()
' Change two rows to identical values after invoking BeginEdit.
table.Rows(0).BeginEdit()
table.Rows(1).BeginEdit()
table.Rows(0)(0) = 100
table.Rows(1)(0) = 100
Try
' Now invoke EndEdit. This will cause the UniqueConstraint
' to be enforced.
table.Rows(0).EndEdit()
table.Rows(1).EndEdit()
Catch e As Exception
' Process exception and return.
Console.WriteLine("Exception of type {0} occurred.", _
e.GetType().ToString())
End Try
End Sub
Private Sub Row_Changed _
(sender As Object, e As System.Data.DataRowChangeEventArgs)
Dim table As DataTable = CType(sender, DataTable)
Console.WriteLine("RowChanged " & e.Action.ToString() _
& ControlChars.Tab & e.Row.ItemArray(0).ToString())
End Sub