2
我想用xml格式将数据库中的数据转换为 使用c#我已经在ino xml格式中转换,但是它没有提供关于在架构主键和外键如何将sql服务器数据库模式加上所有表中的数据转换为xml格式
我的代码是
string[] b = GetAllTables();//array that gives me the name of tables
foreach (string c in b)
{
string sqlText = "SELECT * FROM " + c;
SqlDataAdapter da = new SqlDataAdapter(sqlText, myCon);
da.SelectCommand.CommandType = CommandType.Text;
da.Fill(customer,c);
foreach (DataTable dt1 in customer.Tables)
{
for (int curRow = 0; curRow < dt1.Rows.Count; curRow++)
{
for (int curCol = 0; curCol < dt1.Columns.Count; curCol++)
{
dt1.Rows[curRow][curCol].ToString();
// System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(@"D:\Customer.xml");
}
}
}
}
string xmlDS = customer.GetXml();
customer.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
MessageBox.Show("successfully writed");
xmlSW.Close();
在MS SQL Server中,您可以在查询结尾处添加“SELECT * FROM Table FOR XML AUTO”以及“SELECT * FROM Table FOR XML RAW”。试试你的SQL编辑器,看看结果是否有助于你的最终目标。 – 2013-04-03 18:15:11