To create
\\\
Dim ds as new dataset
dim dt as new datatable
dt.columns.add("TheLastDate",gettype(system.datetime))
dt.rows.add(dt.newrow)
ds.tables.add(dt)
dt.rows(0)("TheLastDate") = date.Now
ds.writeXML("C:\path")
///
To use
\\\
ds.read(XML"C:\path")
dim mydate as datetime = ds.tables(0).rows(0)("TheLastDate")
///
I hope this helps?
Very helpful... It works great!!! I do have one more question though...
It would be great to be able to store object properties so I tried the
code
included below, but it doesn't work. The program complains that the
"Specified cast is not valid". Since the data was written out with a
specific data type, why wouldn't the cast be valid when reading it back
in?
I can break these properties down to simple data types, but I'd rather do
it
this way if it's possible.
'Write settings...
Private Sub Write()
'Declare dataset objects
dim ds as new dataset("Settings")
dim dt as new datatable("Textbox")
'Add columns to the table
dt.columns.add("Foreground", GetType(System.Drawing.Color))
dt.columns.add("Font", gettype(System.Drawing.Font))
'Add a row to the table
dt.Rows.Add(dt.NewRow)
'Add the table to the dataset
ds.Tables.Add(dt)
'Update data in table
dt.Rows(0)("Foreground") = txtBox.Forecolor
dt.Rows(0)("Font") = txtBox.Font
'Write dataset to disk
ds.WriteXML("C:\File.xml")
'Destroy objects
dt = Nothing
ds = Nothing
End Sub
Private Sub Read()
'Declare objects
Dim ds as Dataset
ds.ReadXml("C:\File.xml") '***MISSING FROM NEWS POST
txtBox.Font = ds.Tables("Textbox").Rows(0)("Font")
txtBox.ForeColor = ds.Tables("Textbox").Rows(0)("Foreground")
ds = Nothing
End Sub
'**********************
The resulting file looks like this:
<?xml version="1.0" standalone="yes"?>
<Settings>
<Textbox>
<Foreground>Color [WindowText]</Foreground>
<Font>[Font: Name=Arial, Size=12, Units=3, GdiCharSet=0,
GdiVerticalFont=False]</Font>
</Textbox>
</Settings>