467,168 Members | 984 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,168 developers. It's quick & easy.

Write dataset to XML and back again to dataset?

Before a delete on any table, I would like to write the contents of the
soon-to-be-deleted row to that application's single "graveyard" table
(alternate: or document as coded below).
SQL Server 2005 solution: I would store the tablename, today's date,
username, and the key column values of the soon-to-be deleted row as the
composite key of the new graveyard table row. The soon-to-be-deleted row's
data would be stored in a single xml-type column.
XML File solution: composite key from above would be the name of a
filename.xml file. The data from the soon-to-be-deleted row would be the
xml document. This is done by the following code:

Private Sub WriteXmlToFile(ByVal strGraveYardID As String, _

ByVal ds As DataSet)

'create a file name to write to.

Dim filename As String = "C:\Projects\Human Services\XMLGraveyard\" &
strGraveYardID & ".xml"

'create the FileStream to write with.

Dim myFileStream As New System.IO.FileStream(filename,
System.IO.FileMode.Create)

'create an XmlTextWriter with the fileStream.

Dim myXmlWriter As New System.Xml.XmlTextWriter(myFileStream,
System.Text.Encoding.Unicode)

'write to the file with the WriteXml method.

ds.WriteXml(myXmlWriter)

myXmlWriter.Close()

End Sub
The above works fine. Now, for the question. What about resurrecting the
deleted row from the graveyard row? Is there a way to convert the xml
document (or SQL Server 2005 data column) back into a dataset so that the
row can be re-inserted back into the original table?
Thanks,

Dean Slindee
Nov 23 '05 #1
  • viewed: 1942
Share:
2 Replies
Rob
If you have the XML file you could open the file in VS, then select "Create
Schema" from the XML menu to establish an XSD document. VS will modify your
XML to refer to the XSD file. Save your changes and then you can use the
ReadXML method of the dataset to read the data back into the dataset.

Hope this helps

Rob

"Dean Slindee" wrote:
Before a delete on any table, I would like to write the contents of the
soon-to-be-deleted row to that application's single "graveyard" table
(alternate: or document as coded below).
SQL Server 2005 solution: I would store the tablename, today's date,
username, and the key column values of the soon-to-be deleted row as the
composite key of the new graveyard table row. The soon-to-be-deleted row's
data would be stored in a single xml-type column.
XML File solution: composite key from above would be the name of a
filename.xml file. The data from the soon-to-be-deleted row would be the
xml document. This is done by the following code:

Private Sub WriteXmlToFile(ByVal strGraveYardID As String, _

ByVal ds As DataSet)

'create a file name to write to.

Dim filename As String = "C:\Projects\Human Services\XMLGraveyard\" &
strGraveYardID & ".xml"

'create the FileStream to write with.

Dim myFileStream As New System.IO.FileStream(filename,
System.IO.FileMode.Create)

'create an XmlTextWriter with the fileStream.

Dim myXmlWriter As New System.Xml.XmlTextWriter(myFileStream,
System.Text.Encoding.Unicode)

'write to the file with the WriteXml method.

ds.WriteXml(myXmlWriter)

myXmlWriter.Close()

End Sub
The above works fine. Now, for the question. What about resurrecting the
deleted row from the graveyard row? Is there a way to convert the xml
document (or SQL Server 2005 data column) back into a dataset so that the
row can be re-inserted back into the original table?
Thanks,

Dean Slindee

Nov 23 '05 #2
Dean,

I think that you are easier of with a clone dataset/datatable.

If you want any more help,

Please reply

Cor
Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dean Slindee | last post: by
4 posts views Thread by Filippo Pandiani | last post: by
16 posts views Thread by Geoff Jones | last post: by
13 posts views Thread by processoriented | last post: by
12 posts views Thread by =?Utf-8?B?QW5kcmV3?= | last post: by
15 posts views Thread by Joseph Geretz | last post: by
8 posts views Thread by Matt MacDonald | last post: by
12 posts views Thread by Rainer Queck | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.