Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to store data from sql server database table into xml file? Is it possible to do that ? if yes how??
Posted

Read the data into a DataTable, and use the DataTable.WriteXml[^] method.

C#
DataTable dt = new DataTable("Videos");
using (SqlConnection con = new SqlConnection(GenericData.DBConnection))
    {
    con.Open();
    using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Videos", con))
        {
        da.Fill(dt);
        using (StreamWriter sw = new StreamWriter(@"D:\Temp\videos.xml"))
            {
            dt.WriteXml(sw);
            sw.Flush();
            }
        }
    }


[edit]Eh? Where did the code go? - OriginalGriff[/edit]
 
Share this answer
 
v2
I get an error on "Generic Data"
the name "GenericData" doesn't exist in the current context ? what i shall do ? is there a name space or something related?
 
Share this answer
 
Comments
Ranjith Reddy CSE 18-Jun-12 1:33am    
using System.Collections.Generic ...........This is the Namspace Include it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900