读入多个xml文件 [英] read in multiple xml files

查看:68
本文介绍了读入多个xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码将单个xml文件写入sql表。

你能告诉我如何做一个foreach所以我可以从一个目录中读取多个文件



The following code writes the single xml file to an sql table.
Can you please show me how to do a foreach so I can read in multiple files from a single directory

private void button1_Click(object sender, EventArgs e)
{
    string cs = @"Server=SQLEX\WS19;Database=XML;User Id=sa;Password=;";
    using (SqlConnection con = new SqlConnection(cs))
    {
            DataSet ds = new DataSet();
            ds.ReadXml(@"E:\XML\product.xml");
            DataTable dt1 = ds.Tables["cats"];
            con.Open();
            using (SqlBulkCopy bc = new SqlBulkCopy(con))
            {
                bc.DestinationTableName = "Category";
                bc.ColumnMappings.Add("catClass", "types");
                bc.ColumnMappings.Add("catDefinition", "description");
                bc.ColumnMappings.Add("cattValue", "amount");
                bc.WriteToServer(dt1);
            }               
    }
}





感谢您的帮助或指导



Thank you for any assistance or guidance

推荐答案

看看这里: Directory.GetFiles方法(字符串) [ ^ ] - 在页面底部,您将找到示例代码( ProcessDirectory )。
Take a look here: Directory.GetFiles Method (String)[^] - on the bottom of page, you'll find sample code (ProcessDirectory).


这篇关于读入多个xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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