将数据从XML文件导入SQL数据库 [英] Importing data from XML file to SQL database
问题描述
是否可以将XML文件中的数据导入SQL数据库,如果是,可以如何进行。我有一个XML文件,其中包含大约50 000个条目,我必须做一个应用程序,将操纵这些数据(大多数是读取和比较) - 所以我的关注是用这些数量的操作(和一个非常可能的可能性在未来会有更多)将是非常缓慢和低效率。
如果有其他一些你认为会更好的选择,请指教。
感谢
Is it possible to import data from XML file to a SQL database, and if yes, how would that be done. I have a XML file that contains about 50 000 entries and I have to make an application that would manipulate that data (mostly reading and comparing) - so my concern is that the manipulation with that amount of data (and there is a very likely possibility that in the future there will be even more) would be very slow and inefficient. If there is some other option that you think would be better, please advise. Thanks
推荐答案
您可以使用 SQL Server导入和导出向导。您还可以查看 SQL Server集成服务。如果你想使用C#,那么SQL服务器支持XML数据类型。你可以使用它。
You can use SQL Server Import and Export Wizard. You can also look in SQL Server Integration Services. If you want to use C# then SQL server does support XML data type. You can make use of that.
您还可以尝试读取数据集中的数据,然后使用 BulkInsert 在SQL Server中插入数据
You can also try to read the data in data set and then use BulkInsert to insert data in SQL Server
DataSet reportData = new DataSet();
reportData.ReadXml(Server.MapPath("yourfile.xml"));
SqlConnection connection = new SqlConnection("DB ConnectionSTring");
SqlBulkCopy sbc = new SqlBulkCopy(connection);
sbc.DestinationTableName = "yourXMLTable";
编辑:对于SQL Server 2005,请检查 SQL Server 2005导入/导出向导
For SQL Server 2005 check SQL Server 2005 Import / Export Wizard
这篇关于将数据从XML文件导入SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!