K
Kai Thorsrud
Hi,
I've got a debug/learn function for doing my xml thingie.
I simply want to append data to an xml file. This confuses me, i've looked
at xmldocument, xmldatadocument and from what i understand a DataSet is a
flexible and "easy" (if you know how) way to work with xml files. I've
worked alot with ADO in VB6 so this seemed tempting (i'm still a .net noob
or NOOB)
I've managed to create a schema for my table and i think i know how to add
the data correctly but i
can't manage to update my data back to my DataSet and write the DataSet as
an XMLFile. I've looked on the DataAdapter but i end up wondering how do i
make an OleDB conn to my xml file and i resemble nooo this seems stupid and
bigfoot print'ed since they say .net and xml is like bread and butter. I
just want to use an xml file as a simple database for my app.
Would anyone be so kind to help me out with a updatetable thingie ?
My Code fails on the AcceptChanges which i suppose is because my DataRow
isn't written back to the DataSet but how do i do that ?
Please ignore the bad naming convention this code is mixed with a lot copy
paste from various examples... none covers how to work with just a dataset
and an xml file.. I think i fail to see the wood because of the forest if
you know what i mean
Public Function doCreateNewXmlfile()
Dim ds As New DataSet
Dim col As DataColumn
Dim oDataRow As DataRow
'Create the table structure.
With ds.Tables.Add("Routers")
col = .Columns.Add("IPAddr", GetType(String))
col.MaxLength = 15
col = .Columns.Add("HostName", GetType(String))
col.MaxLength = 90
col = .Columns.Add("LogFileName", GetType(String))
col.MaxLength = 30
End With
' Save our schema representing our table structure
Dim oFileStream As New
System.IO.FileStream(Me.setXmlIpTableFileSchemaName, FileMode.Create)
ds.WriteXmlSchema(oFileStream)
oFileStream.Close()
oFileStream = Nothing
' Create some data in our xmldatabase
Dim row As DataRow = ds.Tables("Routers").NewRow
row("IPAddr") = "192.168.1.1"
row("HostName") = "tower"
row("LogFileName") = "tower_Log"
row.AcceptChanges()
oFileStream = New System.IO.FileStream(Me.setXmlIpTableFileName,
FileMode.Create)
ds.WriteXml(oFileStream)
oFileStream.Close()
oFileStream = Nothing
End Function
Thanks a lot
/Kai
I've got a debug/learn function for doing my xml thingie.
I simply want to append data to an xml file. This confuses me, i've looked
at xmldocument, xmldatadocument and from what i understand a DataSet is a
flexible and "easy" (if you know how) way to work with xml files. I've
worked alot with ADO in VB6 so this seemed tempting (i'm still a .net noob
or NOOB)
I've managed to create a schema for my table and i think i know how to add
the data correctly but i
can't manage to update my data back to my DataSet and write the DataSet as
an XMLFile. I've looked on the DataAdapter but i end up wondering how do i
make an OleDB conn to my xml file and i resemble nooo this seems stupid and
bigfoot print'ed since they say .net and xml is like bread and butter. I
just want to use an xml file as a simple database for my app.
Would anyone be so kind to help me out with a updatetable thingie ?
My Code fails on the AcceptChanges which i suppose is because my DataRow
isn't written back to the DataSet but how do i do that ?
Please ignore the bad naming convention this code is mixed with a lot copy
paste from various examples... none covers how to work with just a dataset
and an xml file.. I think i fail to see the wood because of the forest if
you know what i mean
Public Function doCreateNewXmlfile()
Dim ds As New DataSet
Dim col As DataColumn
Dim oDataRow As DataRow
'Create the table structure.
With ds.Tables.Add("Routers")
col = .Columns.Add("IPAddr", GetType(String))
col.MaxLength = 15
col = .Columns.Add("HostName", GetType(String))
col.MaxLength = 90
col = .Columns.Add("LogFileName", GetType(String))
col.MaxLength = 30
End With
' Save our schema representing our table structure
Dim oFileStream As New
System.IO.FileStream(Me.setXmlIpTableFileSchemaName, FileMode.Create)
ds.WriteXmlSchema(oFileStream)
oFileStream.Close()
oFileStream = Nothing
' Create some data in our xmldatabase
Dim row As DataRow = ds.Tables("Routers").NewRow
row("IPAddr") = "192.168.1.1"
row("HostName") = "tower"
row("LogFileName") = "tower_Log"
row.AcceptChanges()
oFileStream = New System.IO.FileStream(Me.setXmlIpTableFileName,
FileMode.Create)
ds.WriteXml(oFileStream)
oFileStream.Close()
oFileStream = Nothing
End Function
Thanks a lot
/Kai