how to convert database tables into xml files

B

Brahmam

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
 
S

SStory

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
 
J

Jason Hales

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>
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.
 
Joined
Sep 29, 2012
Messages
1
Reaction score
0
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



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

search in google like "createxmlfromdb"
 
Last edited:

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top