how to convert database tables into xml files

Discussion in 'ASP .Net' started by Brahmam, Apr 4, 2006.

  1. Brahmam

    Brahmam Guest

    when i click on import table in C#.net

    we have to retrieve all the tables from the DB and those have to be
    converted into xml files with their respected names

    Can anyone give me the suggestions

    Thanks in Advance
    Brahmi
     
    Brahmam, Apr 4, 2006
    #1
    1. Advertising

  2. Brahmam

    SStory Guest

    Once you have data in a dataset there is a method so save that straight to
    XML; however it may not be in the format you want.

    Shane
    "Brahmam" <> wrote in message
    news:Oa4rrV$...
    > when i click on import table in C#.net
    >
    > we have to retrieve all the tables from the DB and those have to be
    > converted into xml files with their respected names
    >
    > Can anyone give me the suggestions
    >
    > Thanks in Advance
    > Brahmi
    >
    >
     
    SStory, Apr 4, 2006
    #2
    1. Advertising

  3. Brahmam

    Jason Hales Guest

    Here's a little sample. You'll notice that I switch the
    DataColumn.ColumnMapping so show writing out column as attributes and
    also as elements (by default you don't get the schema written out)

    using(DataSet myDataSet = new DataSet())
    {

    using(DataTable myDataTable = new DataTable("MyData"))
    {
    myDataSet.Tables.Add(myDataTable);
    myDataTable.Columns.Add(new DataColumn("EmployeeID", typeof(Int32)));
    myDataTable.Columns.Add(new DataColumn("EmployeeName",
    typeof(string)));

    DataRowCollection rows = myDataTable.Rows;

    DataRow newRow = myDataTable.NewRow();
    newRow["EmployeeID"] = 1;
    newRow["EmployeeName"] = "Jason Hales";
    rows.Add(newRow);

    newRow = myDataTable.NewRow();
    newRow["EmployeeID"] = 2;
    newRow["EmployeeName"] = "Bob Smith";
    rows.Add(newRow);

    foreach(DataColumn column in myDataTable.Columns)
    {
    column.ColumnMapping = MappingType.Attribute;
    }
    myDataSet.WriteXml(@"c:\temp\data with attributes.xml");

    foreach(DataColumn column in myDataTable.Columns)
    {
    column.ColumnMapping = MappingType.Element;
    }
    myDataSet.WriteXml(@"c:\temp\data with elements.xml");


    }
    }

    Results in :
    <?xml version="1.0" standalone="yes"?>
    <NewDataSet>
    <MyData EmployeeID="1" EmployeeName="Jason Hales" />
    <MyData EmployeeID="2" EmployeeName="Bob Smith" />
    </NewDataSet>

    and:
    <?xml version="1.0" standalone="yes"?>
    <NewDataSet>
    <MyData>
    <EmployeeID>1</EmployeeID>
    <EmployeeName>Jason Hales</EmployeeName>
    </MyData>
    <MyData>
    <EmployeeID>2</EmployeeID>
    <EmployeeName>Bob Smith</EmployeeName>
    </MyData>
    </NewDataSet>
     
    Jason Hales, Apr 7, 2006
    #3
  4. If you use SQL Server, you can use FOR XML RAW or FOR XML AUTO in a
    SELECT statement to get the result as XML.

    Brahmam wrote:
    > when i click on import table in C#.net
    >
    > we have to retrieve all the tables from the DB and those have to be
    > converted into xml files with their respected names
    >
    > Can anyone give me the suggestions
    >
    > Thanks in Advance
    > Brahmi
    >
    >
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 7, 2006
    #4
  5. Brahmam

    samu4uhere

    Joined:
    Sep 29, 2012
    Messages:
    1


    Check this download link...
    to convert SQL server Database table into XML...its an Application..

    search in google like "createxmlfromdb"
     
    Last edited: Sep 29, 2012
    samu4uhere, Sep 29, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry Zoroc
    Replies:
    1
    Views:
    963
    Gregory Vaughan
    Jul 12, 2004
  2. Chris Brat
    Replies:
    5
    Views:
    708
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Aug 22, 2006
  3. Juan T. Llibre
    Replies:
    0
    Views:
    425
    Juan T. Llibre
    Jun 12, 2009
  4. Eric S
    Replies:
    11
    Views:
    840
    Eric S
    Jun 17, 2009
  5. Steve D
    Replies:
    4
    Views:
    278
    Steve D
    Jan 10, 2006
Loading...

Share This Page