zoukankan      html  css  js  c++  java
  • sqlhelper写调用存储过程方法

    public static object Proc(string ProcName, SqlParameter[] parm)
            {
                conn.Open();       //最后一个参数为输出参数
                parm[parm.Length - 1].Direction = ParameterDirection.Output;
                using (SqlCommand cmd = new SqlCommand(ProcName,conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (parm != null)
                    {
                        cmd.Parameters.AddRange(parm);
                    }
                    
                    int result = cmd.ExecuteNonQuery();
                }
                conn.Close();       //返回输出的参数,看存储过程中定义的输出参数是什么类型,这里就转换成什么类型
                return (bool)parm[parm.Length - 1].Value;        
            }
    

      

    以上为sqlhelper里面使用存储过程的方法.

    如果调用呢?

    public object ZiJian(int uid,int cid,int jid)
            {
                SqlParameter[] parameter = {
                    new SqlParameter("@uid",SqlDbType.Int),
                    new SqlParameter("@cid",SqlDbType.Int),
                    new SqlParameter("@jid",SqlDbType.Int),
                    new SqlParameter("@result",SqlDbType.Bit)
                };
                parameter[0].Value = uid;
                parameter[1].Value = cid;
                parameter[2].Value = jid;
                parameter[3].Direction = ParameterDirection.Output;
                return SqlHelper.Proc($"Proc_Zijian",parameter);
            }
    

      

    因为存储过程中的参数不固定,所以在这里把使用存储过程的参数组成一个集合,最后一个为输出参数,所以不需要赋值,但是需要指出他是输出参数.parameter[3].Direction = ParameterDirection.Output;

     
    转自 https://www.cnblogs.com/xinqi1995/p/8258129.html
  • 相关阅读:
    活动安排
    中国剩余定理
    欧拉回路
    单词游戏
    Ant Trip
    John's Trip
    太鼓达人
    相框
    原始生物
    Blockade
  • 原文地址:https://www.cnblogs.com/wl-blog/p/13745616.html
Copyright © 2011-2022 走看看