2023年6月21日发(作者:)
批量更新数据(BatchUpdate)批量更新数据(BatchUpdate)///
{ try{ foreach (DataRow row in [0].Rows){Changes();ified();//所有⾏设置为可修改} string cols = (",", columnsName);cols = "[" + e(",", "],[") + "]";SqlCommand cmd = new SqlCommand(("SELECT {2} FROM {0} WHERE {1}", targetTableName, limitWhere, cols), conn);ction = transaction;SqlDataAdapter adapter = new SqlDataAdapter(cmd);SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(adapter);ChangesDuringFill = false;(ds); string updateSQL = ;SqlParameter[] paras = new SqlParameter[]; for (int i = 0; i < ; i++){ //去除⾃增长ID ,根据可控的⾃增Id进⾏更新 if (columnsName[i] != primaryKeyName && columnsName[i] != identity){updateSQL += ("[" + columnsName[i] + "]" + "=@" + columnsName[i] + ",");} if (s[i]. == "Int32"){paras[i] = new SqlParameter("@" + columnsName[i], , 10, columnsName[i]);} else if (s[i]. == "DateTime"){paras[i] = new SqlParameter("@" + columnsName[i], me, 23, columnsName[i]);} else if (s[i]. == "Double"){paras[i] = new SqlParameter("@" + columnsName[i], l, 23, columnsName[i]);} else{paras[i] = new SqlParameter("@" + columnsName[i], ar, -1, columnsName[i]);//-1表⽰⼤于4000的长度}} if (!OrEmpty(updateSQL)){updateSQL = (',');} string limitSql = ("[" + primaryKeyName + "]" + "=@" + primaryKeyName);SqlCommand updateCmd = new SqlCommand(("UPDATE {0} SET {1} WHERE {2}", targetTableName, updateSQL, limitSql)); //设置不修改源dRowSource = ;Command = updateCmd;ge(paras);ction = transaction;dTimeout = 36000;//超时时间BatchSize = batchNum;(ds, targetTableName);Changes();(); return true;} catch (Exception ex){ck(); return false; throw ex;} finally{();e();}}}}
2023年6月21日发(作者:)
批量更新数据(BatchUpdate)批量更新数据(BatchUpdate)///
{ try{ foreach (DataRow row in [0].Rows){Changes();ified();//所有⾏设置为可修改} string cols = (",", columnsName);cols = "[" + e(",", "],[") + "]";SqlCommand cmd = new SqlCommand(("SELECT {2} FROM {0} WHERE {1}", targetTableName, limitWhere, cols), conn);ction = transaction;SqlDataAdapter adapter = new SqlDataAdapter(cmd);SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(adapter);ChangesDuringFill = false;(ds); string updateSQL = ;SqlParameter[] paras = new SqlParameter[]; for (int i = 0; i < ; i++){ //去除⾃增长ID ,根据可控的⾃增Id进⾏更新 if (columnsName[i] != primaryKeyName && columnsName[i] != identity){updateSQL += ("[" + columnsName[i] + "]" + "=@" + columnsName[i] + ",");} if (s[i]. == "Int32"){paras[i] = new SqlParameter("@" + columnsName[i], , 10, columnsName[i]);} else if (s[i]. == "DateTime"){paras[i] = new SqlParameter("@" + columnsName[i], me, 23, columnsName[i]);} else if (s[i]. == "Double"){paras[i] = new SqlParameter("@" + columnsName[i], l, 23, columnsName[i]);} else{paras[i] = new SqlParameter("@" + columnsName[i], ar, -1, columnsName[i]);//-1表⽰⼤于4000的长度}} if (!OrEmpty(updateSQL)){updateSQL = (',');} string limitSql = ("[" + primaryKeyName + "]" + "=@" + primaryKeyName);SqlCommand updateCmd = new SqlCommand(("UPDATE {0} SET {1} WHERE {2}", targetTableName, updateSQL, limitSql)); //设置不修改源dRowSource = ;Command = updateCmd;ge(paras);ction = transaction;dTimeout = 36000;//超时时间BatchSize = batchNum;(ds, targetTableName);Changes();(); return true;} catch (Exception ex){ck(); return false; throw ex;} finally{();e();}}}}
发布评论