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
  • 相关阅读:
    jQuery中jsonp的跨域处理,no access-control-allow-origin,unexpected token
    doT中嵌套for循环的使用
    c++ new带括号和不带括号
    python装饰器之使用情景分析
    Python中classmethod与staticmethod区别
    python作用域 scope
    duck type鸭子类型
    EAFP和LBYL 两种防御性编程风格
    c++重载、覆盖和隐藏
    c++ 名字粉碎(name mangling)
  • 原文地址:https://www.cnblogs.com/wl-blog/p/13745616.html
Copyright © 2011-2022 走看看