Imports System.Data.DataSetExtensions
Private customers As DataTable = New DataTable("Customers")
If IO.File.Exists("data.xml") Then
customers.ReadXml("data.xml")
customers.Columns.AddRange({New DataColumn("ID", GetType(UInt32)), New DataColumn("Name"), New DataColumn("Date of Birth", GetType(DateTime))})
Console.WriteLine("Main Menu")
Console.WriteLine("1) Find Customer")
Console.WriteLine("2) Add Customer")
Dim input As UInteger = 0
Console.Write("Selection: ")
If Not UInteger.TryParse(Console.ReadLine, input) OrElse (input <> 1 AndAlso input <> 2) Then
Console.WriteLine("Please enter a valid number that is either 1 or 2.")
Loop Until input = 1 OrElse input = 2
Console.WriteLine("Find Customer Menu")
Console.WriteLine("Type the customer's name and hit enter to search. Or enter the value '1' to go back to the main menu.")
Dim input As String = Console.ReadLine
Dim rows = From customer In customers.AsEnumerable() Where customer.Field(Of String)("Name").Equals(input, StringComparer.OrdinalIgnoreCase) Select customer
Console.WriteLine("Name - Date of Birth")
For Each customer As DataRow In rows
Console.WriteLine(customer.Field(Of String)("Name") & " - " & customer.Field(Of DateTime)("Date of Birth").ToShortDateString())
Console.WriteLine("End of results. Press enter to go back to the main menu.")
Console.WriteLine("Add Customer Menu")
Console.WriteLine("Type the customer's name and hit enter. Or enter the value '1' to go back to the main menu.")
Dim input As String = Console.ReadLine
Dim dob As DateTime = Nothing
Dim dobInput As String = String.Empty
Console.WriteLine("Type the customer's date of birth and hit enter. Or enter the value '1' to go back to the main menu.")
dobInput = Console.ReadLine
If dobInput <> "1" AndAlso Not DateTime.TryParse(dobInput, dob) Then
Console.WriteLine("Please enter a valid date.")
Loop Until dob <> Nothing OrElse dobInput = "1"
customers.Rows.Add({customers.Rows.Count, input, dob})
customers.WriteXml("data.xml")
Console.WriteLine("Customer added. Press enter to go back to the main menu.")