How to Export Full SQL Table to XML

后端 未结 2 1908
野趣味
野趣味 2021-02-10 04:06

My primary coding ideal is on .net applications.. So I have limited skill with application design.

I am trying to export an entire table from a database (Using a view) t

相关标签:
2条回答
  • 2021-02-10 04:28

    You might want to take a look at how you can write queries which output is XML.
    There are many examples and tutorials around on the internet about this. this http://msdn.microsoft.com/en-us/library/bb510462.aspx is one of them.

    If i am not mistaken the output returned should be a string with the complete XML stuff inside of it.

    0 讨论(0)
  • 2021-02-10 04:32

    You can use a SqlDataAdapter and System.Data.DataSet to load a DataTable, which will write to XML.

    const string strSql = "SELECT * FROM vwGetStaffDetails";
    
    using (SqlCommand sqlComm = new SqlCommand(strSql, DataConn.Connect()) { CommandType = CommandType.Text })
    {
        SqlDataAdapter da = new SqlDataAdapter(sqlComm);
        DataSet ds = new DataSet();
        da.Fill(ds);
        ds.Tables[0].WriteXml(@"C:\Temp\text.xml");
    }
    

    Edit Using this method you'll remove the XML code from SQL and let .NET convert everything. I've changed your SQL command to reflect this.

    0 讨论(0)
提交回复
热议问题