Solved

VB.Net - Save DataTable from a Dataset To XML

Posted on 2004-09-02
8
449 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
Comment Utility
DataSet.WriteXML(path) and DataSet.ReadXML(path)

Bob
0
 
LVL 1

Author Comment

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

Expert Comment

by:Bob Learned
Comment Utility
How many tables does the dataset have?

Bob
0
 
LVL 5

Expert Comment

by:thenrich
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:Vartana
Comment Utility
more then 1
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now