Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 操作数据集_C#_.net_Xml_Dataset - Fatal编程技术网

C# 操作数据集

C# 操作数据集,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/

我在操作/导航数据集时遇到问题,我将其作为自动生成的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/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();
        }
    }
}