C# 操作数据集
我在操作/导航数据集时遇到问题,我将其作为自动生成的XML文件拉入。我的目标是将某些节点放入SQL表的列中 我的XMLC# 操作数据集,c#,.net,xml,dataset,C#,.net,Xml,Dataset,我在操作/导航数据集时遇到问题,我将其作为自动生成的XML文件拉入。我的目标是将某些节点放入SQL表的列中 我的XML <root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/
<root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
<submission name="entry0">
<entry name="firstName">Name</entry>
<entry name="School">The University of College</entry>
<entry name="ExpectedYearofEntry">2019</entry>
<entry name="mailingAddress">Some st</entry>
</submission>
<submission name..........
</root>
名称
大学大学
2019
一些圣
您可以使用类似于SqlBulkCopy的方法有效地将所有这些行插入表中。不过,您必须对数据集中的每个表执行此操作
好例子:
一旦有了要插入的数据表
if (dt.Rows.Count > 0)
{
string consString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
using (SqlConnection con = new SqlConnection(consString))
{
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
{
//Set target table
sqlBulkCopy.DestinationTableName = "dbo.Customers";
//Map the DataTable columns with the database table
sqlBulkCopy.ColumnMappings.Add("Id", "CustomerId");
sqlBulkCopy.ColumnMappings.Add("Name", "Name");
sqlBulkCopy.ColumnMappings.Add("Country", "Country");
con.Open();
sqlBulkCopy.WriteToServer(dt);
con.Close();
}
}
}
if (dt.Rows.Count > 0)
{
string consString = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
using (SqlConnection con = new SqlConnection(consString))
{
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
{
//Set target table
sqlBulkCopy.DestinationTableName = "dbo.Customers";
//Map the DataTable columns with the database table
sqlBulkCopy.ColumnMappings.Add("Id", "CustomerId");
sqlBulkCopy.ColumnMappings.Add("Name", "Name");
sqlBulkCopy.ColumnMappings.Add("Country", "Country");
con.Open();
sqlBulkCopy.WriteToServer(dt);
con.Close();
}
}
}