Re: Dump SQL Server database to XML through C#
- From: Jenden0@xxxxxxxxx
- Date: 12 Jun 2006 16:16:28 -0700
Yea, I thought about that. I'm trying to use visual studio's
auto-generated stuff as much as I can (as I find its easier for other
people to update later on)... I may have to just go with the SQL
though.
That's easiest. You can just create a DataSet and keep adding tables to it.
EG:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string constr="Data Source=(local); Initial Catalog=test;Integrated
Security=true";
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
DataTable tables = new DataTable();
string sqlTables = "select name from sys.Tables where schema_id =
1";
using (SqlDataReader rdr = new SqlCommand(sqlTables,
con).ExecuteReader())
{
tables.Load(rdr);
}
DataSet db = new DataSet();
foreach (DataRow table in tables.Rows)
{
string tableName = (string)table["name"];
string sql = string.Format("select * from [{0}]", tableName);
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.TableMappings.Add("Table", tableName);
da.Fill(db);
}
db.WriteXml(Console.Out,XmlWriteMode.WriteSchema);
}
}
}
}
David
.
- References:
- Dump SQL Server database to XML through C#
- From: Jenden0
- Re: Dump SQL Server database to XML through C#
- From: David Browne
- Dump SQL Server database to XML through C#
- Prev by Date: Re: Looking for practice programming problems
- Next by Date: Re: Asynch Sockets over UDP: How do you Know when a socket dissconnects
- Previous by thread: Re: Dump SQL Server database to XML through C#
- Next by thread: Argument Exception with Double.CompareTo
- Index(es):
Relevant Pages
|