/// <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动态赋值 更新需要的数据