嗨,我想在 asp.net 3.5 c# for windows application.so 中将我的 .xml 文件导入 sql server 数据库。所以尽可能快地提供 m rply。
问问题
2169 次
4 回答
2
this might help you http://support.microsoft.com/kb/316005
this code snippet might be helpful
DataSet reportData = new DataSet();
reportData.ReadXml(Server.MapPath(”report.xml”));
SqlConnection connection = new SqlConnection(”CONNECTION STRING”);
SqlBulkCopy sbc = new SqlBulkCopy(connection);
sbc.DestinationTableName = “report_table”;
//if your DB col names don’t match your XML element names 100%
//then relate the source XML elements (1st param) with the destination DB cols
sbc.ColumnMappings.Add(”campaign”, “campaign_id”);
sbc.ColumnMappings.Add(”cost”, “cost_USD”);
connection.Open();
refer http://www.akamarketing.com/blog/135-importing-xml-into-sql-server-table-aspnet.html
于 2010-01-22T11:02:44.313 回答
0
It's not brilliant, but you could read an XML file into a dataset and then use a data adapter to then populate the database...that would require very few lines of code, but not something you'd really want to hold onto...more of a once off dataload.
于 2010-01-22T11:01:29.760 回答
0
如果这是您正在做的被认为是预处理的事情,我会考虑使用 SSIS:将XML 导入 SQL Server
于 2010-01-22T13:40:05.650 回答
0
首先你 2 使用 xml 解析器操作 d xml 文件,以便 xml 文档中的元素转换为其他应用程序可以访问的对象
于 2010-01-22T11:18:00.283 回答