473,418 Members | 2,233 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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
2 2096
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dean Slindee | last post by:
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...
4
by: Filippo Pandiani | last post by:
I have a grid that shows the file list from a folder. On the postback, how do I get a Dataset from this grid? Thanks, Filippo.
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
13
by: processoriented | last post by:
I am trying to find the best approach to do something here... situation is this... One of the tables in my dataset is a "Work Order" table with information about what needs to be done and where. ...
12
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me if I am using it right or not? Imports System.Data.sqlclient Imports System.Data Public Class Form1 Inherits...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
8
by: Matt MacDonald | last post by:
Hi all, First of all, I am not trying to be the guy who comes in here shouting his mouth off at Microsoft. However, ever sinse I started using typed datasets in VS2005 I have been fighting with a...
12
by: Rainer Queck | last post by:
Hi NG, I have no idea why, but since a while a dataset refuses to write to a specific xml file. I get the error message "Der Zugriff auf den Pfad...
1
by: jc | last post by:
RE: Why use a CollectionBase class here vs dataset or dataview? I'm looking at some vb.net 2005 code that was generated from a homegrown Codesmith Template that generate all of the retreival and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.