datatable批量更新数据

 /// <summary>
        /// 批量更新服务器数据库 数据
        /// </summary>
        /// <param name="dt">要更新的表的数据</param>
        /// <param name="sql">要更新的目标服务器数据</param>
        /// <param name="connectionString">服务器数据库连接字符串</param>
        /// <param name="isAccount">是否是更新发送账号或者已发送完邮件true是发送账号、false是已发送邮件</param>
        /// <returns></returns>
        public static int UpdateSoMuch(DataTable dt,string sql, string connectionString,bool isAccount)
        {
            DataTable dtt=new DataTable ();
            using (OracleConnection conn = new OracleConnection(connectionString))
            {
                OracleCommand cmd = new OracleCommand(sql,conn);
                OracleDataAdapter oda = new OracleDataAdapter(cmd);
                oda.Fill(dtt);
                OracleCommandBuilder cb = new OracleCommandBuilder(oda);
                if (isAccount)
                {
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        dtt.Rows[i]["sendcount"] = dt.Rows[i]["sendcount"];
                        dtt.Rows[i]["LAST_SEND_TIME"] = dt.Rows[i]["LAST_SEND_TIME"];
                        dtt.Rows[i]["state"] = 0;
                    } 
                }
                else
                {
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        dtt.Rows[i]["flag"] = dt.Rows[i]["flag"];
                        dtt.Rows[i]["endtime"] = dt.Rows[i]["endtime"];
                        dtt.Rows[i]["sendtime"] = dt.Rows[i]["sendtime"];
                        dtt.Rows[i]["sendoktime"] = dt.Rows[i]["sendoktime"];
                        dtt.Rows[i]["failedreason"] = dt.Rows[i]["failedreason"];
                        dtt.Rows[i]["send_email"] = dt.Rows[i]["send_email"];
                        //dtt.Rows[i]["send_account"] = dt.Rows[i]["send_account"];
                        dtt.Rows[i]["failcount"] = dt.Rows[i]["failcount"];
                    } 
                }
                return oda.Update(dtt);
            }
        }

//有时 更新不了数据 主要几点:查找数据的sql、

缺少OracleCommandBuilder cb = new OracleCommandBuilder(oda);
datatable的datarow的rowstate状态未变更 所以目前给dtt动态赋值 更新需要的数据

转载于:https://www.cnblogs.com/Iyce/p/3169882.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值