/// <summary> /// 执行传入的存储过程名,返回SqlDataReader对象 /// </summary> /// <param name="strProName">存储过程名称</param> /// <param name="stProParameters">存储过程变量</param> /// <param name="DR">返回的SqlDataReader对象</param> /// <returns></returns> public SqlDataReader YX_PROCEDURE_DataReader(string strProName, YX_ProceducreParameter[] stProParameters) { SqlConnection con = createCon(); con.Open(); SqlDataReader DR = null; try { L_Comm = new SqlCommand(strProName, con); //SqlCommand L_Comm; L_Comm.CommandType = CommandType.StoredProcedure; for (int i = 0; i < stProParameters.Length; ++i) //注意不是“i++”! { YX_ProceducreParameter stProPar = stProParameters[i]; SqlParameter sp = new SqlParameter(stProPar.L_strPName, stProPar.L_dbtPType, stProPar.L_iPSize); sp.Direction = stProPar.L_pdDirection; sp.Value = stProPar.L_obPValue; L_Comm.Parameters.Add(sp); } DR = L_Comm.ExecuteReader(CommandBehavior.CloseConnection); iState = 0; } catch { iState = -1; } con.Close(); return(DR); }
/// <summary> /// 执行存储过程操作,没有返回结果 /// </summary> /// <param name="strProName">存储过程名称</param> /// <param name="stProParameters">存储过程变量</param> /// <returns></returns> public int YX_PROCEDURE_NonQuery(string strProName, YX_ProceducreParameter[] stProParameters) { SqlConnection con = createCon(); con.Open(); try { L_Comm = new SqlCommand(strProName, con); L_Comm.CommandType = CommandType.StoredProcedure; for (int i = 0; i < stProParameters.Length; i++) { YX_ProceducreParameter stProPar = stProParameters[i]; SqlParameter sp = new SqlParameter(stProPar.L_strPName, stProPar.L_dbtPType, stProPar.L_iPSize); sp.Direction = stProPar.L_pdDirection; sp.Value = stProPar.L_obPValue; L_Comm.Parameters.Add(sp); } L_Comm.ExecuteNonQuery(); iState = 0; // L_Comm.Dispose(); } catch { iState = -1; } finally { con.Close(); } return(iState); }
/// <summary> /// 执行传入的存储过程名和参数结构体,返回DataSet对象 /// </summary> /// <param name="strProName"></param> /// <param name="stProParameters"></param> /// <returns></returns> public DataSet YX_PROCEDURE_DataSet(string strProName, YX_ProceducreParameter[] stProParameters) { SqlConnection con = createCon(); con.Open(); DataSet ds = new DataSet(); L_Comm = new SqlCommand(strProName, con); L_Comm.CommandType = CommandType.StoredProcedure; for (int i = 0; i < stProParameters.Length; ++i)//注意,不是“i++”! { YX_ProceducreParameter stProPar = stProParameters[i]; SqlParameter sp = new SqlParameter(stProPar.L_strPName, stProPar.L_dbtPType, stProPar.L_iPSize); sp.Direction = stProPar.L_pdDirection; sp.Value = stProPar.L_obPValue; L_Comm.Parameters.Add(sp); } SqlDataAdapter da = new SqlDataAdapter(L_Comm); try { da.Fill(ds); } catch { } finally { da.Dispose(); con.Close(); } return(ds); }