JPERKS1985
asked on
Export DataGrid to XML or update data in the dataset and then export to XML
I need to know how to either export my datagrid directly to an xml file (preferred) or modify specific items within the dataset and then export the xml.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would think serialisation would be the way to go.... (because it just is, usually)
Pass your dataset into and outof these functions, they return the DS as text that you can save or whatever.
You may like to modify them to read and write directly to files..
Public Function SerializeDataset(ByVal DatasetToSerialise As Data.Dataset) As String
Dim oXS As System.Xml.Serialization.X mlSerializ er
Try
oXS = New System.Xml.Serialization.X mlSerializ er(GetType (Data.Data set))
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim oStmW As IO.StringWriter
oStmW = New IO.StringWriter()
Try
oXS.Serialize(oStmW, DatasetToSerialise)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
oStmW.Close()
Return oStmW.ToString
End Function
Public Function DeserialiseDataset(ByVal SerializedObject As String) As DataSet
Dim oXS As Xml.Serialization.XmlSeria lizer = New Xml.Serialization.XmlSeria lizer(GetT ype(Data.D ataSet))
Dim oStmR As IO.StringReader
oStmR = New IO.StringReader(Serialized Object)
Dim NewDataSet As Data.DataSet= CType(oXS.Deserialize(oStm R), Data.DataSet)
oStmR.Close()
Return NewDataSet
End Function
Pass your dataset into and outof these functions, they return the DS as text that you can save or whatever.
You may like to modify them to read and write directly to files..
Public Function SerializeDataset(ByVal DatasetToSerialise As Data.Dataset) As String
Dim oXS As System.Xml.Serialization.X
Try
oXS = New System.Xml.Serialization.X
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim oStmW As IO.StringWriter
oStmW = New IO.StringWriter()
Try
oXS.Serialize(oStmW, DatasetToSerialise)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
oStmW.Close()
Return oStmW.ToString
End Function
Public Function DeserialiseDataset(ByVal SerializedObject As String) As DataSet
Dim oXS As Xml.Serialization.XmlSeria
Dim oStmR As IO.StringReader
oStmR = New IO.StringReader(Serialized
Dim NewDataSet As Data.DataSet= CType(oXS.Deserialize(oStm
oStmR.Close()
Return NewDataSet
End Function
if u wonna know about dataset's and how to work with dataset u might checkout this link
http://www.homeandlearn.co.uk/NET/nets12p9.html