出口SQL Server数据库表到XML使用LINQ [英] Export SQL Server Database Table to XML Using Linq

查看:168
本文介绍了出口SQL Server数据库表到XML使用LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道该怎么做简单的LINQ到XML。导出SQL Server数据库表中的数据。像遵循一个简单的查询将工作:

I know how to do simple Linq To XML. Export a sql server database table data. A simple query like follow will work:

xmlDoc = new XElement("TestPoints",
                from test in myDB.TestPoints
                select
                new XElement("TestPoint",
                    new XElement("Id", test.Id),
                    new XElement("Value", test.Value),
                    new XElement("Time", test.Time),
                    new XElement("TestId", test.TestId)
                    )
                );
            xmlDoc.Save("test.xml");

然而,在这种情况下,我需要指定每个数据库列那些我需要出口。我需要的是要导出的有30多个列的表。现在,它的有点痛苦,使创建新的XElement的这种重复任务。 有什么办法来转储全部表及其所有列/行到一个XML文件在LINQ容易吗?如果没有外部指定每一列即可。谢谢你。

However, in this case, i need to specify every database column those I need to export. What I need is to export a table which have more than 30 columns. Now, its a bit painful to make such repetitively task of creating new XElement. Is there any way to dump the full table and all its columns/rows to a xml file in LinQ easily please? Without specify each column externally. Thanks.

推荐答案

在数据表中放置数据的SQL Server表

Put Data of sql server table in DataTable

比使用 DataTable.WriteXml 会做你的任务很容易。

and than use DataTable.WriteXml will do your task easily.

这篇关于出口SQL Server数据库表到XML使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆