public DataSet GetDataSetByProc(string ProcName, CmdParameter[] parms) { SqlParameter[] pas = CFunctions.ConvertToSqlParameter(parms); DataSet dt = new DataSet();; using (SqlConnection conn = new SqlConnection(strConn)) { using (SqlDataAdapter da = new SqlDataAdapter(ProcName, conn)) try { da.SelectCommand.CommandType = CommandType.StoredProcedure; if (pas != null) { da.SelectCommand.Parameters.AddRange(pas); } da.Fill(dt); //command.Parameters["ReturnValue"].Value; } catch (Exception ex) { CFunctions.HandleException(System.Reflection.MethodBase.GetCurrentMethod().Name + ":" + ProcName, ex); throw (ex); } } return(dt); }
/// <summary> /// 根据存储过程获取DataTable,参数的修改会被返回 /// </summary> /// <param name="ProcName"></param> /// <param name="parms"></param> /// <returns></returns> public DataTable GetTableByProc(string ProcName, ref CmdParameter[] parms) { SqlParameter[] pas = CFunctions.ConvertToSqlParameter(parms); DataTable dt = new DataTable();; using (SqlConnection conn = new SqlConnection(strConn)) { using (SqlDataAdapter da = new SqlDataAdapter(ProcName, conn)) { try { da.SelectCommand.CommandType = CommandType.StoredProcedure; if (pas != null) { da.SelectCommand.Parameters.AddRange(pas); } dt.TableName = ProcName; da.Fill(dt); da.SelectCommand.Parameters.Clear(); } catch (Exception ex) { CFunctions.HandleException(System.Reflection.MethodBase.GetCurrentMethod().Name + ":" + ProcName, ex); throw (ex); } try { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = ProcName; cmd.CommandType = CommandType.StoredProcedure; foreach (SqlParameter sp in pas) { cmd.Parameters.Add(sp); } cmd.ExecuteNonQuery(); for (int i = 0; i < pas.Length; i++) { pas[i] = cmd.Parameters[i]; } parms = CFunctions.RecoverParameter(pas); } catch (Exception ex) { CFunctions.HandleException(System.Reflection.MethodBase.GetCurrentMethod().Name, ex); // throw (ex); } } } return(dt); }
public int ExcuteProc(string ProcName, CmdParameter[] parms) { SqlParameter[] pas = CFunctions.ConvertToSqlParameter(parms); return(ExcuteSQL(ProcName, pas, CommandType.StoredProcedure)); }