Hi
I just cant get this to work. The idea is to add a user to an xmlfile. It works when when a new file is created. But when i want to add a dataset to an existing file it fails.
- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!
I just cant get this to work. The idea is to add a user to an xmlfile. It works when when a new file is created. But when i want to add a dataset to an existing file it fails.
Code:
Try
Dim dsSet As New DataSet("Users")
Dim dtTables As New DataTable("User")
Dim drRow As DataRow
dtTables.Columns.Add("UserId", System.Type.GetType("System.Int32"))
dtTables.Columns.Add("Password", System.Type.GetType("System.String"))
dtTables.Columns.Add("FName", System.Type.GetType("System.String"))
dtTables.Columns.Add("LName", System.Type.GetType("System.String"))
drRow = dtTables.NewRow()
drRow("UserId") = txtUserID.Text
drRow("Password") = txtPassword.Text
drRow("FName") = txtFName.Text
drRow("LName") = txtLName.Text
dtTables.Rows.Add(drRow)
dsSet.Tables.Add(dtTables)
saveDataSet(dsSet)
Me.Close()
Catch ex As Exception
logError(ex)
End Try
End Sub
Public Function saveDataSet(ByVal ds As DataSet) As Boolean
Try
strPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly(). _
GetName().CodeBase)
strPath = strPath & "\" & "users2.xml"
Dim fs As New FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write)
Dim xw As New XmlTextWriter(fs, System.Text.Encoding.UTF8)
ds.WriteXml(xw, System.Data.XmlWriteMode.WriteSchema)
xw.Close()
Catch ex As Exception
Throw ex
End Try
End Function
- - - - - - - - - - - - - - - - - -
Im three apples high, Im blue, and i most certainly like that cold beer that should be every mans right after a hard days work!