Public Class ProductionOrder
Public Property SalesOrderID As Integer
Public Property CustomerName As String
Public Property DespatchMethod As String
End Class
Public Class ProductionOrderCollection
Inherits List(Of ProductionOrder)
Public Sub New()
'Declare the Handled Exception Collection
Dim handledException = CustomErrorCollection.GetCustomErrorCollection
'Declare Data Reader
Dim drd As DbDataReader
'Get Data from Data DLL
drd = ProductionData.Orders
While drd.Read
Dim order As New ProductionOrder
order.SalesOrderID = drd.GetInt32(0)
order.CustomerName = drd.GetString(1)
order.DespatchMethod = drd.GetString(2)
Me.Add(order)
End While
End Sub
End Class
Module Module1
Private data As New Orders(From i As Integer In Enumerable.Range(0, 50) Select New Order() With {.ID = i, .CustomerName = String.Format("Customer{0}", i), .DispatchMethod = If(i Mod 3 = 0, "Plane", If(i Mod 2 = 0, "Train", "Automobile"))})
Sub Main()
Dim customerOrders As New Orders(data)
Console.WriteLine("Before update")
Console.WriteLine(customerOrders(25))
For Each [order] In data
If [order].DispatchMethod = "Plane" Then
[order].DispatchMethod = "Boeing 747"
ElseIf [order].DispatchMethod = "Train" Then
[order].DispatchMethod = "B&O"
Else
[order].DispatchMethod = "Mom Drove You"
End If
Next
customerOrders.Clear()
customerOrders.AddRange(data)
Console.WriteLine("After update")
Console.WriteLine(customerOrders(25))
Console.ReadLine()
End Sub
End Module
Class Order
Public Property ID() As Integer
Public Property CustomerName() As String
Public Property DispatchMethod() As String
Public Overrides Function ToString() As String
Return String.Format("{{ ID: {0}; Customer Name: {1}; Dispatch Method: {2} }}", ID, CustomerName, DispatchMethod)
End Function
End Class
Class Orders
Inherits List(Of Order)
Public Sub New()
MyBase.New()
End Sub
Public Sub New(capacity As Integer)
MyBase.New(capacity)
End Sub
Public Sub New(collection As IEnumerable(Of Order))
MyBase.New(collection)
End Sub
End Class
Or you can check if the item exists and update it's individual field(s); e.g. -
Module Module1
Private data As New Orders(From i As Integer In Enumerable.Range(0, 50) Select New Order() With {.ID = i, .CustomerName = String.Format("Customer{0}", i), .DispatchMethod = If(i Mod 3 = 0, "Plane", If(i Mod 2 = 0, "Train", "Automobile"))})
Sub Main()
Dim customerOrders As New Orders(data)
Console.WriteLine("Before update")
Console.WriteLine(customerOrders(25))
For Each [order] In data
If [order].DispatchMethod = "Plane" Then
[order].DispatchMethod = "Boeing 747"
ElseIf [order].DispatchMethod = "Train" Then
[order].DispatchMethod = "B&O"
Else
[order].DispatchMethod = "Mom Drove You"
End If
Next
For Each [order] In data
Dim current = customerOrders.FirstOrDefault(Function(x) x.ID = [order].ID)
If current IsNot Nothing Then
current.CustomerName = [order].CustomerName
current.DispatchMethod = [order].DispatchMethod
Else
customerOrders.Add([order])
End If
Next
Console.WriteLine("After update")
Console.WriteLine(customerOrders(25))
Console.ReadLine()
End Sub
End Module
Class Order
Public Property ID() As Integer
Public Property CustomerName() As String
Public Property DispatchMethod() As String
Public Overrides Function ToString() As String
Return String.Format("{{ ID: {0}; Customer Name: {1}; Dispatch Method: {2} }}", ID, CustomerName, DispatchMethod)
End Function
End Class
Class Orders
Inherits List(Of Order)
Public Sub New()
MyBase.New()
End Sub
Public Sub New(capacity As Integer)
MyBase.New(capacity)
End Sub
Public Sub New(collection As IEnumerable(Of Order))
MyBase.New(collection)
End Sub
End Class
Each of the above produce the following output -The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
Open in new window