Public Sub xmlAccountWriter(ByVal ID As String, ByVal Username As String, ByVal Password As String, ByVal GUID As String, ByVal FirstName As String, ByVal LastName As String, ByVal BirthDate As String, ByVal PhoneNumber As String)
'The path and filename where you want to store this account XML file
Dim myPath As String = "C:\accounts.xml" ' << Change this
'First, check to see if we have an existing XML file
If IO.File.Exists(myPath) = False Then
'It doesn't exists, so we'll create a new file.
'First, create a table to store our values in.
Dim gridtable As DataTable = New DataTable("Account Info")
Dim gridtable_column0 As DataColumn = New DataColumn("Username")
Dim gridtable_column1 As DataColumn = New DataColumn("Password")
Dim gridtable_column2 As DataColumn = New DataColumn("GUID")
Dim gridtable_column3 As DataColumn = New DataColumn("FirstName")
Dim gridtable_column4 As DataColumn = New DataColumn("LastName")
Dim gridtable_column5 As DataColumn = New DataColumn("BirthDate")
Dim gridtable_column6 As DataColumn = New DataColumn("PhoneNumber")
gridtable.Columns.Add(gridtable_column0)
gridtable.Columns.Add(gridtable_column1)
gridtable.Columns.Add(gridtable_column2)
gridtable.Columns.Add(gridtable_column3)
gridtable.Columns.Add(gridtable_column4)
gridtable.Columns.Add(gridtable_column5)
gridtable.Columns.Add(gridtable_column6)
'Now add the first row to this table, with the data we were supplied
Dim table_row As DataRow
table_row = gridtable.NewRow
table_row("Username") = Username
table_row("Password") = Password
table_row("GUID") = GUID
table_row("FirstName") = FirstName
table_row("LastName") = LastName
table_row("BirthDate") = BirthDate
table_row("PhoneNumber") = PhoneNumber
'Add the row
gridtable.Rows.Add(table_row)
'Now write it as an XML file to our path that we picked above
gridtable.WriteXml(myPath)
Else
'If we are here, then there is a pre-existing XML file. We'll add onto it.
Dim myXMLDataSet As New DataSet
'Read in the existing XML File
myDataSet.ReadXml(myPath)
'Create a new row of information to add to it
Dim table_row As DataRow
table_row = myDataSet.Tables(0).NewRow
table_row("Username") = Username
table_row("Password") = Password
table_row("GUID") = GUID
table_row("FirstName") = FirstName
table_row("LastName") = LastName
table_row("BirthDate") = BirthDate
table_row("PhoneNumber") = PhoneNumber
'Add the row
myDataSet.Tables(0).Rows.Add(table_row)
'Now write it as an XML file to our path that we picked above
myDataSet.WriteXml(myPath)
End If
End Sub