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

  • 相关阅读:
    474. Ones and Zeroes
    [LeetCode]464. Can I Win
    413. Arithmetic Slices
    numpy学习(布尔型索引)
    numpy学习(数组和标量之间的运算切片)
    numpy学习(数组的定义及基础属性)
    关于静态显示游标的遍历
    关于oracle的数组
    shutil模块
    开源库(不定义更新)
  • 原文地址:https://www.cnblogs.com/chixiaojin/p/2437411.html
Copyright © 2011-2022 走看看