protected override ExeResEdm UpdateDtToDB(DataTable dtInfos, string strComFields = "*") { ExeResEdm dBResEdm = new ExeResEdm(); string strTableName = dtInfos.TableName; try { using (System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection(connstr)) { conn.Open(); System.Data.OracleClient.OracleCommand cmd = conn.CreateCommand(); cmd.CommandText = GetColumnsNameSql(strTableName, strComFields); System.Data.OracleClient.OracleDataAdapter adapter = new System.Data.OracleClient.OracleDataAdapter(cmd); adapter.UpdateCommand = new System.Data.OracleClient.OracleCommandBuilder(adapter).GetUpdateCommand(); adapter.Update(dtInfos.GetChanges()); dtInfos.AcceptChanges(); } } catch (Exception ex) { dBResEdm.Module = "UpdateDtToDB方法"; dBResEdm.ExBody = ex; dBResEdm.ErrCode = 1; return(dBResEdm); } return(dBResEdm); }
protected override ExeResEdm UpdateDsToDB(DataSet dsTables, Dictionary <string, string> dicDtMainFields = null) { ExeResEdm dBResEdm = new ExeResEdm(); int n = 0; try { using (System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection(connstr)) { conn.Open(); System.Data.OracleClient.OracleTransaction tsOprate = conn.BeginTransaction(); try { System.Data.OracleClient.OracleCommand cmd = conn.CreateCommand(); cmd.Transaction = tsOprate; foreach (DataTable dtTemp in dsTables.Tables) { string strComFields = "*"; if (dicDtMainFields != null && dicDtMainFields.Count > 0 && dicDtMainFields.ContainsKey(dtTemp.TableName)) { strComFields = !string.IsNullOrEmpty(dicDtMainFields[dtTemp.TableName]) ? dicDtMainFields[dtTemp.TableName]: strComFields; } cmd.CommandText = GetColumnsNameSql(dtTemp.TableName, strComFields); System.Data.OracleClient.OracleDataAdapter adapter = new System.Data.OracleClient.OracleDataAdapter(cmd); var dtChanges = dtTemp.GetChanges(); adapter.FillSchema(dtChanges, SchemaType.Mapped); //new added if (dtChanges != null) //是添加或更新 { adapter.UpdateCommand = new System.Data.OracleClient.OracleCommandBuilder(adapter).GetUpdateCommand(); n += adapter.Update(dtChanges); dtTemp.AcceptChanges(); } else //是删除 { adapter.DeleteCommand = new System.Data.OracleClient.OracleCommandBuilder(adapter).GetDeleteCommand(); for (int i = dtTemp.Rows.Count - 1; i >= 0; i--) { dtTemp.Rows[i].Delete(); } n += adapter.Update(dtTemp); } } dsTables.AcceptChanges(); tsOprate.Commit(); } catch (Exception ex) { tsOprate.Rollback(); dBResEdm.Module = "UpdateDsToDB方法"; dBResEdm.ExBody = ex; dBResEdm.ErrCode = 1; return(dBResEdm); } } } catch (Exception ex) { dBResEdm.Module = "UpdateDsToDB方法"; dBResEdm.ExBody = ex; dBResEdm.ErrCode = 1; return(dBResEdm); } dBResEdm.ExeNum = n; return(dBResEdm); }
public int Update(System.Data.DataSet dataSet, string srcTable) { return(_da.Update(dataSet, srcTable)); }