Solved

VB.Net - Save DataTable from a Dataset To XML

Posted on 2004-09-02
8
455 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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