📄 dataset1.vb
字号:
Return CType(Me.Rows.Find(New Object() {CustomerID}),CustomerRow)
End Function
Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Return Me.Rows.GetEnumerator
End Function
Public Overrides Function Clone() As DataTable
Dim cln As CustomerDataTable = CType(MyBase.Clone,CustomerDataTable)
cln.InitVars
Return cln
End Function
Friend Sub InitVars()
Me.columnCustomerID = Me.Columns("CustomerID")
Me.columnAttribName = Me.Columns("AttribName")
Me.columnCompanyName = Me.Columns("CompanyName")
Me.columnContact = Me.Columns("Contact")
Me.columnPhone = Me.Columns("Phone")
Me.columnFax = Me.Columns("Fax")
Me.columnAddress = Me.Columns("Address")
End Sub
Private Sub InitClass()
Me.columnCustomerID = New DataColumn("CustomerID", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnCustomerID)
Me.columnAttribName = New DataColumn("AttribName", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnAttribName)
Me.columnCompanyName = New DataColumn("CompanyName", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnCompanyName)
Me.columnContact = New DataColumn("Contact", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnContact)
Me.columnPhone = New DataColumn("Phone", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnPhone)
Me.columnFax = New DataColumn("Fax", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnFax)
Me.columnAddress = New DataColumn("Address", GetType(System.String), Nothing, System.Data.MappingType.Element)
Me.Columns.Add(Me.columnAddress)
Me.Constraints.Add(New UniqueConstraint("Constraint1", New DataColumn() {Me.columnCustomerID}, true))
Me.columnCustomerID.AllowDBNull = false
Me.columnCustomerID.Unique = true
Me.columnAttribName.AllowDBNull = false
End Sub
Public Function NewCustomerRow() As CustomerRow
Return CType(Me.NewRow,CustomerRow)
End Function
Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow
Return New CustomerRow(builder)
End Function
Protected Overrides Function GetRowType() As System.Type
Return GetType(CustomerRow)
End Function
Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowChanged(e)
If (Not (Me.CustomerRowChangedEvent) Is Nothing) Then
RaiseEvent CustomerRowChanged(Me, New CustomerRowChangeEvent(CType(e.Row,CustomerRow), e.Action))
End If
End Sub
Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowChanging(e)
If (Not (Me.CustomerRowChangingEvent) Is Nothing) Then
RaiseEvent CustomerRowChanging(Me, New CustomerRowChangeEvent(CType(e.Row,CustomerRow), e.Action))
End If
End Sub
Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowDeleted(e)
If (Not (Me.CustomerRowDeletedEvent) Is Nothing) Then
RaiseEvent CustomerRowDeleted(Me, New CustomerRowChangeEvent(CType(e.Row,CustomerRow), e.Action))
End If
End Sub
Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowDeleting(e)
If (Not (Me.CustomerRowDeletingEvent) Is Nothing) Then
RaiseEvent CustomerRowDeleting(Me, New CustomerRowChangeEvent(CType(e.Row,CustomerRow), e.Action))
End If
End Sub
Public Sub RemoveCustomerRow(ByVal row As CustomerRow)
Me.Rows.Remove(row)
End Sub
End Class
<System.Diagnostics.DebuggerStepThrough()> _
Public Class CustomerRow
Inherits DataRow
Private tableCustomer As CustomerDataTable
Friend Sub New(ByVal rb As DataRowBuilder)
MyBase.New(rb)
Me.tableCustomer = CType(Me.Table,CustomerDataTable)
End Sub
Public Property CustomerID As String
Get
Return CType(Me(Me.tableCustomer.CustomerIDColumn),String)
End Get
Set
Me(Me.tableCustomer.CustomerIDColumn) = value
End Set
End Property
Public Property AttribName As String
Get
Return CType(Me(Me.tableCustomer.AttribNameColumn),String)
End Get
Set
Me(Me.tableCustomer.AttribNameColumn) = value
End Set
End Property
Public Property CompanyName As String
Get
Try
Return CType(Me(Me.tableCustomer.CompanyNameColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException("無法取得值,因為它是 DBNull。", e)
End Try
End Get
Set
Me(Me.tableCustomer.CompanyNameColumn) = value
End Set
End Property
Public Property Contact As String
Get
Try
Return CType(Me(Me.tableCustomer.ContactColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException("無法取得值,因為它是 DBNull。", e)
End Try
End Get
Set
Me(Me.tableCustomer.ContactColumn) = value
End Set
End Property
Public Property Phone As String
Get
Try
Return CType(Me(Me.tableCustomer.PhoneColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException("無法取得值,因為它是 DBNull。", e)
End Try
End Get
Set
Me(Me.tableCustomer.PhoneColumn) = value
End Set
End Property
Public Property Fax As String
Get
Try
Return CType(Me(Me.tableCustomer.FaxColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException("無法取得值,因為它是 DBNull。", e)
End Try
End Get
Set
Me(Me.tableCustomer.FaxColumn) = value
End Set
End Property
Public Property Address As String
Get
Try
Return CType(Me(Me.tableCustomer.AddressColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException("無法取得值,因為它是 DBNull。", e)
End Try
End Get
Set
Me(Me.tableCustomer.AddressColumn) = value
End Set
End Property
Public Function IsCompanyNameNull() As Boolean
Return Me.IsNull(Me.tableCustomer.CompanyNameColumn)
End Function
Public Sub SetCompanyNameNull()
Me(Me.tableCustomer.CompanyNameColumn) = System.Convert.DBNull
End Sub
Public Function IsContactNull() As Boolean
Return Me.IsNull(Me.tableCustomer.ContactColumn)
End Function
Public Sub SetContactNull()
Me(Me.tableCustomer.ContactColumn) = System.Convert.DBNull
End Sub
Public Function IsPhoneNull() As Boolean
Return Me.IsNull(Me.tableCustomer.PhoneColumn)
End Function
Public Sub SetPhoneNull()
Me(Me.tableCustomer.PhoneColumn) = System.Convert.DBNull
End Sub
Public Function IsFaxNull() As Boolean
Return Me.IsNull(Me.tableCustomer.FaxColumn)
End Function
Public Sub SetFaxNull()
Me(Me.tableCustomer.FaxColumn) = System.Convert.DBNull
End Sub
Public Function IsAddressNull() As Boolean
Return Me.IsNull(Me.tableCustomer.AddressColumn)
End Function
Public Sub SetAddressNull()
Me(Me.tableCustomer.AddressColumn) = System.Convert.DBNull
End Sub
End Class
<System.Diagnostics.DebuggerStepThrough()> _
Public Class CustomerRowChangeEvent
Inherits EventArgs
Private eventRow As CustomerRow
Private eventAction As DataRowAction
Public Sub New(ByVal row As CustomerRow, ByVal action As DataRowAction)
MyBase.New
Me.eventRow = row
Me.eventAction = action
End Sub
Public ReadOnly Property Row As CustomerRow
Get
Return Me.eventRow
End Get
End Property
Public ReadOnly Property Action As DataRowAction
Get
Return Me.eventAction
End Get
End Property
End Class
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -