public override I3MsgInfo UpdataTable(DataTable dataTable, DbTransaction aTran) { if (!active) { return(new I3MsgInfo(false, "连接已断开,无法执行sql语句")); } bool have = _tableList.Contains(dataTable); if (!have) { return(new I3MsgInfo(false, "此表未被ieData.SqlData填充过,无法将其更新到数据源")); } I3DataSqlAda tmp = (I3DataSqlAda)_tableList[dataTable]; DataTable upTable = dataTable.GetChanges(); if (upTable == null) { return(I3MsgInfo.Default); } if (aTran == null) { SqlTransaction st = connection.BeginTransaction(); try { tmp.Transaction = st; tmp.Adapter.Update(upTable); st.Commit(); dataTable.AcceptChanges(); return(I3MsgInfo.Default); } catch (Exception ex) { st.Rollback(); return(new I3MsgInfo(false, ex.Message, ex)); } finally { st.Dispose(); } } else { tmp.Transaction = (SqlTransaction)aTran; tmp.Adapter.Update(upTable); return(I3MsgInfo.Default); } }
public override void DisposeDataTable(DataTable dataTable) { bool have = _tableList.Contains(dataTable); if (!have) { return; } I3DataSqlAda tmp = (I3DataSqlAda)_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) { I3DataSqlAda tmp = (I3DataSqlAda)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, "连接已断开,无法执行sql语句")); } if (dataTable.TableName == "") { dataTable.TableName = Guid.NewGuid().ToString().ToUpper(); } try { I3DataSqlAda tmp = null; bool have = _tableList.Contains(dataTable); if (have) { tmp = (I3DataSqlAda)_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.Adapter.SelectCommand.Parameters.Add(paramList[i]); } } tmp.Adapter.Fill(dataTable); //tmp.SelectCommand.Parameters.Clear(); } else { tmp = new I3DataSqlAda(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 = (SqlTransaction)aTran; } else { tmp.SelectCommand.Transaction = null; } tmp.Adapter.Fill(dataTable); //tmp.SelectCommand.Parameters.Clear(); //这里如果删除,则增加数据后,Upadate时会报错,必须声明标题变量,见最后面的注解 //但是,之前会什么要加上这句? } return(I3MsgInfo.Default); } catch (Exception ex) { return(new I3MsgInfo(false, ex.Message, ex)); } }