zoukankan      html  css  js  c++  java
  • asp.net调用存储过程1

    1,传入参数,传出参数

    public int GetTeam1Id(string userId)
            {
                int team1ID = -1;
                string strSPName = "PDM.PRODNAME_PHONEINFO_PKG.GET_TEAM1_ID";
                using (OracleConnection dbConnection = new OracleConnection(helper.mConnectionString))
                {
                    dbConnection.Open();

                    OracleCommand dbCommand = new OracleCommand();
                    dbCommand.CommandType = CommandType.StoredProcedure;
                    dbCommand.CommandText = strSPName;
                    dbCommand.Connection = dbConnection;

                    dbCommand.Parameters.Add("PS_USER_ID", userId);
                    dbCommand.Parameters.Add("PS_TEAM1_ID", OracleType.Number);
                    dbCommand.Parameters["PS_TEAM1_ID"].Direction = ParameterDirection.Output;

                    try
                    {
                        dbCommand.ExecuteNonQuery();
                        team1ID = int.Parse(dbCommand.Parameters["PS_TEAM1_ID"].Value.ToString());
                    }
                    catch
                    {
                        dbConnection.Close();
                        dbConnection.Dispose();
                    }
                    if (dbConnection.State == ConnectionState.Open)
                    {
                        dbConnection.Close();
                    }
                    dbConnection.Dispose();
                  
                }
                return team1ID;

            }

    2,

    存储过程的读取一般是
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
    SqlCommand cmd;
    这是个形式
    cmd = new SqlCommand("sp_你的过程", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add(new SqlParameter("@Type", SqlDbType.Int));
    cmd.Parameters["@Type"].Value = 1;
    cmd.Parameters.Add(new SqlParameter("@YourName", SqlDbType.NVarChar, 40));
    cmd.Parameters["@YourName"].Value = GoodsName.Text.Trim();

    GridView1.DataSource = GetDataSet(你的数据库操作,作为显示的源);
    GridView1.DataKeyNames = new String[] { "id" };
    GridView1.DataBind();
    这个是GridView的绑定方法
    记忆力下降,日常日志
  • 相关阅读:
    [BZOJ 1066] [SCOI2007] 蜥蜴 【最大流】
    [BZOJ 1084] [SCOI2005] 最大子矩阵 【DP】
    [BZOJ 1070] [SCOI2007] 修车 【费用流】
    [BZOJ 1878] [SDOI2009] HH的项链
    [BZOJ 3110] [Zjoi2013] K大数查询 【树套树】
    [HDOJ 1171] Big Event in HDU 【完全背包】
    Shell基本语法---函数
    Shell基本语法---shell数组
    Shell基本语法---while语句
    Shell基本语法---for语句
  • 原文地址:https://www.cnblogs.com/yushuo/p/4301778.html
Copyright © 2011-2022 走看看