zoukankan      html  css  js  c++  java
  • 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动态赋值 更新需要的数据

  • 相关阅读:
    C 获取编译日期函数
    C# HttpWebRequest 使用,一个Http分析Demo
    C# 字节序调整
    char/wchar_t之间的互转MultiByteToWideChar和WideCharToMultiByte的用法
    前导声明代替头文件依赖和交叉包含
    MFC network address control使用
    [收藏]POSIX标准
    带引用计数的智能指针
    C# string byte[] 转换
    DIV随鼠标滚动
  • 原文地址:https://www.cnblogs.com/Iyce/p/3169882.html
Copyright © 2011-2022 走看看