• 记录一下C#+Oracle批量插入的一个方法


    public bool insertOracle(DataTable dataTable, string sql) //  Oracle sql 查询的是表头
            {
                string ConnStr = WirelessCenterDAL.Common.GetConnDMS1;
                using (OracleConnection conn = new OracleConnection(ConnStr))
                {
                    try
                    {
                        OracleCommand cmd = new OracleCommand(sql, conn);
                        OracleDataAdapter adapter = new OracleDataAdapter(cmd);
                        OracleCommandBuilder cb = new OracleCommandBuilder(adapter);
                        DataTable dsNew = new DataTable();
                        int count = adapter.Fill(dsNew);
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            DataRow dr = dsNew.NewRow();
                            for (int j = 0; j < dataTable.Columns.Count; j++)
                            {
                                dr[dsNew.Columns[j].ColumnName] = dataTable.Rows[i][j];
                            }
                            dsNew.Rows.Add(dr);
                        }
                        count = adapter.Update(dsNew);
                        adapter.UpdateBatchSize = 5000;
                        //adapter.Update(dataTable);
                        return true;
                    }
                    catch (Exception ex)
                    {
                        //LogHelper.WriteErrLog("insertOracle", ex.Message);
                        return false;
                    }
                }
            }
    

      

  • 相关阅读:
    When You Get Troubles
    CentOS 6.8升级到7+
    Tomcat服务器搭建
    Percona Server 安装
    VirtualBox中如何使虚拟机能够上网?
    CentOS
    xen安装
    SSH免密码设置
    打造绿色版的RobotFramework
    零散知识记录-Jira的安装
  • 原文地址:https://www.cnblogs.com/qianlovebeijixiong/p/4158020.html
Copyright © 2020-2023  润新知