zoukankan      html  css  js  c++  java
  • C# 获取存储过程 返回的参数Output

    public  IList<Gname> GetReadFlei(int fid)
            {
                SqlParameter[] par = { new SqlParameter("@fid",fid),
                                      new SqlParameter("@RecordCount",SqlDbType.NVarChar,30)
                                     };
                par[1].Direction = ParameterDirection.Output;

                SqlDataReader DR = SQLHelp.ExecuteReader("StroGetTest", CommandType.StoredProcedure, par);
                IList<Gname> List = new List<Gname>();
               
                while (DR.Read())
                {
                    Gname sw = new Gname();
                    sw.id = DR.GetInt32(0);
                    sw.gname = DR.GetString(1);
                    sw.gdir = DR.GetString(2);
                    sw.gfla = DR.GetString(3);
                    List.Add(sw);
                }
                
                DR.Close();
                this.Label1.Text = par[1].Value.ToString();
                
                return List;
            }

    public static SqlDataReader ExecuteReader(string cmdText, CommandType cmdType, params SqlParameter[] cmdParms) 

            {
                SqlCommand cmd = new SqlCommand();
                SqlConnection conn = new SqlConnection(Constr);

                try
                {
                    ProCommand(cmd, conn, cmdText, cmdType,cmdParms);
                    SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    //cmd.Parameters.Clear();//放到这里,返回参数会被清空。
                    return rdr;
                }
                catch
                {
                    conn.Close();
                    throw;
                }
            }

    注意:cmd.Parameters.Clear()不能用,否用返回参数会被清空

    CREATE PROCEDURE  StroGetTest
    @fid int ,
    @RecordCount NVarChar(30) Output
    AS

    SELECT @RecordCount=count(1FROM gname WHERE fid=@fid;
    SELECT id,gname,gdir,gfla FROM Gname WHERE fid=@fid;
    GO

  • 相关阅读:
    springboot项目搭建
    linux之scp
    docker文件拷贝
    vue数据绑定不刷新可能情况
    css弹框
    jqgrid跨站脚本漏洞解决
    springboot配置文件加载顺序
    git之在eclipse上玩(一)
    windows系统日志位置
    maven
  • 原文地址:https://www.cnblogs.com/chixiaojin/p/2437411.html
Copyright © 2011-2022 走看看