private object DoGetRC1Value(DbCommand cmd) { try { return(cmd.ExecuteScalar()); } catch (DbException ex) { throw HandleDbAccessException(cmd.Connection, ex, cmd); } catch (Exception e) { string errorMsg = "获取RC1值失败" + "\r\n" + DbAccessHelper.GetDbCommandErrorMsg(cmd.Connection, cmd); throw new DbAccessException(errorMsg, e); } }
private int DoExecCommand(DbCommand cmd) { try { int result = cmd.ExecuteNonQuery(); return(result); } catch (DbException ex) { throw HandleDbAccessException(cmd.Connection, ex, cmd); } catch (Exception ex) { string errorMsg = "执行DbCommand失败" + "\r\n" + DbAccessHelper.GetDbCommandErrorMsg(cmd.Connection, cmd); throw new DbAccessException(errorMsg, ex); } }
private DataSet DoGetDataSetByCommand(DbCommand cmd) { using (DbDataAdapter adp = _engine.CreateDataAdapter()) { try { adp.SelectCommand = cmd; DataSet ds = new DataSet(); adp.Fill(ds); return(ds); } catch (Exception ex) { string errorMsg = "获取DataSet失败" + "\r\n" + DbAccessHelper.GetDbCommandErrorMsg(cmd.Connection, cmd); throw new DbAccessException(errorMsg, ex); } } }
protected override DbAccessException HandleDbAccessException(DbConnection db, DbException ex, params DbCommand[] cmdList) { var sqlEx = ex as SqlException; string errorMsg; switch (sqlEx.Number) { case 2627: errorMsg = "主键冲突" + "\n" + DbAccessHelper.GetDbCommandErrorMsg(db, cmdList); return(new DbAccessException(errorMsg, ex)); case 2601: errorMsg = "索引冲突" + "\n" + DbAccessHelper.GetDbCommandErrorMsg(db, cmdList); return(new DbAccessException(errorMsg, ex)); default: errorMsg = "抛出执行SQL命令错误异常" + "\n" + DbAccessHelper.GetDbCommandErrorMsg(db, cmdList); return(new DbAccessException(errorMsg, ex)); } }