码迷,mamicode.com
首页 > 数据库 > 详细

[C#对Oracle操作]C#操作调用Orcale存储过程有参数

时间:2016-02-26 23:31:12      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
        /// 获取ERP固定资产计提数据
        /// </summary>
        /// <param name="strCompanyCode">公司代码</param>
        /// <param name="strClient">应用环境</param>
        /// <param name="strLanguage">语言</param>
        /// <param name="strRealDeprarea">账套代码:‘01’、‘02’、‘03’</param>
        /// <param name="strFiscalYear">会计年度</param>
        /// <param name="strMonth">会计月度:‘mm’</param>
        /// <returns>DataTable数据集</returns>
        public static DataTable getData(string strCompanyCode, string strClient, string strLanguage, string strRealDeprarea, string strFiscalYear, string strMonth)
        {
            OracleConnection myOracleConnection = null;
            try
            {

                DataTable dt = new DataTable();
                myOracleConnection = new OracleConnection();
                myOracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings["FTERP"].ConnectionString;
                myOracleConnection.Open();
                OracleCommand cmd = new OracleCommand("FXA_MAINVALUEINFO", myOracleConnection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("v_companycode", OracleType.Char).Direction = ParameterDirection.Input; //指明传入的参数是给Oracle存储过程用的
                cmd.Parameters["v_companycode"].Value = strCompanyCode;
                cmd.Parameters.Add("v_client", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_client"].Value = strClient;
                cmd.Parameters.Add("v_language", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_language"].Value = strLanguage;
                cmd.Parameters.Add("v_realdeprarea", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_realdeprarea"].Value = strRealDeprarea;
                cmd.Parameters.Add("v_fiscalyear", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_fiscalyear"].Value = strFiscalYear;
                cmd.Parameters.Add("v_postperiod", OracleType.Char).Direction = ParameterDirection.Input;
                cmd.Parameters["v_postperiod"].Value = strMonth;
                cmd.Parameters.Add("v_returnvalue", OracleType.Float).Direction = ParameterDirection.Output;
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                da.Fill(dt);
                string eval = cmd.Parameters["v_returnvalue"].Value.ToString();
                //myOracleConnection.Close();
                DataTable dtResult = dt.Clone();
                foreach (DataRow dr in dt.Rows)
                {
                    dtResult.Rows.Add(dr.ItemArray);
                }
                return dtResult;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (myOracleConnection.State == ConnectionState.Open)
                {
                    myOracleConnection.Close();
                }
            }


        }
如下是Oracle的存储过程

CREATE OR REPLACE PROCEDURE BZREPDB.FXA_MAINVALUEINFO (
   v_companycode    IN     CHAR,
   v_client         IN     CHAR,
   v_language       IN     CHAR,
   v_realdeprarea   IN     CHAR,
   v_fiscalyear     IN     CHAR,
   v_postperiod     IN     CHAR,
   v_returnvalue       OUT NUMBER
)

 

[C#对Oracle操作]C#操作调用Orcale存储过程有参数

标签:

原文地址:http://www.cnblogs.com/beeone/p/5221987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!