Solved

VB.Net - Save DataTable from a Dataset To XML

Posted on 2004-09-02
8
453 Views
Last Modified: 2012-05-05
I want to save Only the datatable ( RamTable ) to xml

i need both read and write functions please.
0
Comment
Question by:Vartana
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11968012
DataSet.WriteXML(path) and DataSet.ReadXML(path)

Bob
0
 
LVL 1

Author Comment

by:Vartana
ID: 11968027
I DOnt want to save all the datatables in the dataset
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11968070
How many tables does the dataset have?

Bob
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:thenrich
ID: 11968227
Create a new dataset with only the table you want then do what Bob suggested above.

'DataSet.WriteXML(path) and DataSet.ReadXML(path)

Bob'
0
 
LVL 1

Author Comment

by:Vartana
ID: 11968242
more then 1
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 11969208
Hi there... try this..

    Sub WriteTableDataToXML(ByVal DS As DataSet, ByVal TableIndex As Int32, ByVal FileName As String)
        Dim TempDS As New DataSet
        TempDS.Tables.Add(DS.Tables(TableIndex))
        TempDS.WriteXml(FileName)
    End Sub

call it as , WriteTableDataToXML([DataSet Name],[0-based index of the table in dataset],[.xml file name to store in double quotes])

Make similar approach for reading too...
-Baan
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11969231
oops... there was, little problem with the code...
it is fixed now...

    Sub WriteTableDataToXML(ByVal DS1 As DataSet, ByVal TableIndex As Int32, ByVal FileName As String)
        Dim TempDS As New DataSet
        Dim DT As New DataTable
        DT = DS1.Tables(TableIndex).Copy
        TempDS.Tables.Add(DT)
        TempDS.WriteXml(FileName)
    End Sub

-Baan
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11969273
To read...

     Sub ReadTableDataFromXML(ByVal DS1 As DataSet, ByVal TableIndex As Int32, ByVal FileName As String)
        Dim TempDS As New DataSet
        TempDS.ReadXml(FileName)
        Dim DT As New DataTable
        DT = TempDS.Tables(TableIndex).Copy
        DS1.Tables.Add(DT)
    End Sub
call it as... ReadTableDataFromXML([Receiving DataSet Name],[0-based index of the table in XML file],[.xml file name to read from in double quotes])

-Baan
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question