Last active
November 4, 2016 17:41
-
-
Save pedroinfo/6919155681214e607186beb2e695774d to your computer and use it in GitHub Desktop.
DataSet To Xml (Convert Multiple Tables to XML file)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string connectionString = "Server=192.168.2.56;Database=NEWDB;User Id=SA;Password=123456;"; | |
var conn = new SqlConnection(connectionString); | |
conn.Open(); | |
var tables = new[] { "Categories", "CustomerCustomerDemo", "Employees", "Territories" }; | |
var sb = new StringBuilder(); | |
foreach (var table in tables) | |
{ | |
var ds = new DataSet(); | |
var query = "SELECT * FROM " + table + " "; | |
var cmd = new SqlCommand(query, conn); | |
var da = new SqlDataAdapter(cmd); | |
da.Fill(ds, table); | |
sb.AppendLine(ds.GetXml()); | |
} | |
File.WriteAllText(@"c:\\temp\arquivo.xml", "<root>"+ sb.ToString() + "</root>"); | |
conn.Close(); | |
conn.Dispose(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment