public override I3MsgInfo UpdataTable(DataTable dataTable, DbTransaction aTran) { if (!active) { return(new I3MsgInfo(false, "连接已断开,无法更新DataTable")); } bool have = _tableList.Contains(dataTable); if (!have) { return(new I3MsgInfo(false, "此表未被ieData.SqlData填充过,无法将其更新到数据源")); } I3DataOleAda tmp = (I3DataOleAda)_tableList[dataTable]; DataTable upTable = dataTable.GetChanges(); if (upTable == null) { return(I3MsgInfo.Default); } if (aTran == null) { OleDbTransaction ot = connection.BeginTransaction(); try { tmp.Transaction = ot; tmp.Adapter.Update(upTable); ot.Commit(); dataTable.AcceptChanges(); return(I3MsgInfo.Default); } catch (Exception ex) { ot.Rollback(); return(new I3MsgInfo(false, ex.Message, ex)); } finally { ot.Dispose(); } } else { tmp.Transaction = (OleDbTransaction)aTran; tmp.Adapter.Update(upTable); return(I3MsgInfo.Default); } }
public override void DisposeDataTable(DataTable dataTable) { bool have = _tableList.Contains(dataTable); if (!have) { return; } I3DataOleAda tmp = (I3DataOleAda)_tableList[dataTable]; tmp.Adapter.Dispose(); if (tmp.CommandBuilder != null) { tmp.CommandBuilder.Dispose(); } _tableList.Remove(dataTable); }
public override void Close() { try { foreach (DictionaryEntry de in _tableList) { I3DataOleAda tmp = (I3DataOleAda)de.Value; tmp.Adapter.Dispose(); if (tmp.CommandBuilder != null) { tmp.CommandBuilder.Dispose(); } } _tableList.Clear(); connection.Close(); connection.Dispose(); } catch (Exception ex) { throw new Exception("数据连接关闭失败", ex); } }
public override I3MsgInfo FillTable(DataTable dataTable, bool clear, string sqlText, DbParameter[] paramList, DbTransaction aTran, I3Command command) { if (!active) { return(new I3MsgInfo(false, "连接已断开,无法填充DataTable")); } if (dataTable.TableName == "") { dataTable.TableName = Guid.NewGuid().ToString().ToUpper(); } try { I3DataOleAda tmp = null; bool have = _tableList.Contains(dataTable); if (have) { tmp = (I3DataOleAda)_tableList[dataTable]; if (clear) { dataTable.Clear(); } tmp.SelectCommand.CommandText = sqlText; tmp.SelectCommand.Parameters.Clear(); if (paramList != null) { for (int i = 0; i < paramList.Length; i++) { tmp.SelectCommand.Parameters.Add(paramList[i]); } } tmp.Adapter.Fill(dataTable); //tmp.SelectCommand.Parameters.Clear(); } else { tmp = new I3DataOleAda(connection, sqlText, command); tmp.SelectCommand.Parameters.Clear(); if (paramList != null) { for (int i = 0; i < paramList.Length; i++) { tmp.SelectCommand.Parameters.Add(paramList[i]); } } _tableList.Add(dataTable, tmp); if (aTran != null) { tmp.SelectCommand.Transaction = (OleDbTransaction)aTran; } else { tmp.SelectCommand.Transaction = null; } tmp.Adapter.Fill(dataTable); //tmp.SelectCommand.Parameters.Clear(); } return(I3MsgInfo.Default); } catch (Exception ex) { return(new I3MsgInfo(false, ex.Message, ex)); } }