public DataSet GetDataSet_Cmd(string commandText, CommandType commandType, params DbParameter[] parameters) { SqlTransaction trans = Transaction; SqlConnection conn = null; SqlCommand cmd = null; bool needDispose = true; //针对没有事务的情况 try { cmd = new SqlCommand(); cmd.CommandTimeout = CommandTimeout; if (trans == null) { conn = this.Connection; if (conn == null) { conn = OpenNew(this.connectionString, false); } else { needDispose = false;//采用共享的数据库连接,使用完毕后不需关闭 } DbHelperUtil.PrepareCommand(cmd, conn, (SqlTransaction)null, commandType, commandText, parameters); } else { DbHelperUtil.PrepareCommand(cmd, trans.Connection, trans, commandType, commandText, parameters); } using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataSet ds = new DataSet(); da.Fill(ds); return(ds); } } catch (Exception ex) { RollBack(); if (ex is SqlException && ((SqlException)ex).Number == 99999) { throw new RFException(ex.Message); } throw ex; } finally { if (needDispose) { Close(conn); } if (cmd != null) { cmd.Parameters.Clear(); } } }
public object GetValue(string commandText, CommandType commandType, params DbParameter[] parameters) { SqlTransaction trans = Transaction; SqlConnection conn = null; SqlCommand cmd = null; bool needDispose = true; //针对没有事务的情况 try { cmd = new SqlCommand(); cmd.CommandTimeout = CommandTimeout; if (trans == null) { conn = this.Connection; if (conn == null) { conn = OpenNew(this.connectionString, false); } else { needDispose = false;//采用共享的数据库连接,使用完毕后不需关闭 } DbHelperUtil.PrepareCommand(cmd, conn, (SqlTransaction)null, commandType, commandText, parameters); } else { DbHelperUtil.PrepareCommand(cmd, trans.Connection, trans, commandType, commandText, parameters); } object obj = cmd.ExecuteScalar();//结果集中的第一行第一列 return(obj); } catch (Exception ex) { RollBack(); if (ex is SqlException && ((SqlException)ex).Number >= 50000) { throw new RFException(ex.Message); } throw ex; } finally { if (needDispose) { Close(conn); } if (cmd != null) { cmd.Parameters.Clear(); } } }
public DataSet GetDataSet(string spName, params object[] paraValues) { if (paraValues != null) { SqlParameter[] commandParameters = SqlDbParameterCache.GetSpParameterSet(ConnectionString, spName, false); DbHelperUtil.AssignParameterValues(commandParameters, paraValues);; return(GetDataSet(spName, commandParameters)); } else { return(GetDataSet(spName, (DbParameter[])null)); } }
public object GetValue(string spname, params object[] paraValues) { if (paraValues != null) { SqlParameter[] commandParameters = SqlDbParameterCache.GetSpParameterSet(ConnectionString, spname, false); DbHelperUtil.AssignParameterValues(commandParameters, paraValues);; return(GetValue(spname, CommandType.StoredProcedure, commandParameters)); } else { return(GetValue(spname, CommandType.StoredProcedure, (DbParameter)null)); } }
public int ExcuteSP(string spName, DataRow dataRow) { if (dataRow != null) { SqlParameter[] commandParameters = SqlDbParameterCache.GetSpParameterSet(ConnectionString, spName, false); DbHelperUtil.AssignParameterValues(commandParameters, dataRow);; return(ExcuteSP(spName, commandParameters)); } else { return(ExcuteSP(spName, (DbParameter[])null)); } }