zoukankan      html  css  js  c++  java
  • C#批量将数据插入SQLServer数据库

                     Database db = CreateDatabase();
                    var varConnnection = db.CreateConnection();     //获取连接字符串对象
                    SqlBulkCopy sqlBulkcopy = new SqlBulkCopy(varConnnection.ConnectionString);
                    sqlBulkcopy.DestinationTableName = "T_ACl_User_Function";   //数据库表名字
                    sqlBulkcopy.BatchSize = dt.Rows.Count;
                    try
                    {
                        varConnnection.Open();
                        if (dt != null && dt.Rows.Count != 0)
                        {
                            sqlBulkcopy.WriteToServer(dt);  //批量插入到数据库中
                            init = 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        varConnnection.Close();
                        if (sqlBulkcopy != null)
                            sqlBulkcopy.Close();
                    }
                    return init;

  • 相关阅读:
    WindowsManager 程序(一) 控制窗口的程序
    SQLServer导入导出资料的方法
    CSS收集(1)
    SQLReporting Service
    WindowsManager 程序(二)
    Microsoft 预发行软件 Visual Studio Team System 2008 测试版 2 Team Suite
    Ajax Pro 使用
    一个获取文件的ICON类
    MyCodeBar我的代码片段管理工具
    ADSL自动断拨号类
  • 原文地址:https://www.cnblogs.com/leaflife/p/7000941.html
Copyright © 2011-2022 走看看