RT,单独接收会,但不会同时接收,请大神赐教

解决方案 »

  1.   

    output值不是通过输出参数返回,获取存储参数的值就可以了。
      

  2.   

    Northwind数据库建存储过程:
    CREATE PROCEDURE QUERY_CUSTOMERS(@CITY NVARCHAR(50), @COUNT INT OUTPUT)
    AS
    BEGIN
    SELECT @COUNT = COUNT(1)
    FROM   CUSTOMERS
    WHERE  CITY = @CITY;

    SELECT *
    FROM   CUSTOMERS
    WHERE  CITY = @CITY
    END
    调用:
    SqlConnection connection = new SqlConnection();
    string connStr = "server=.;uid=sa;pwd=sa;database=northwind";
    connection.ConnectionString = connStr;
    connection.Open();
    SqlCommand command = connection.CreateCommand();
    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "QUERY_CUSTOMERS";
    SqlParameter param1 = new SqlParameter("@city", "London");
    param1.Direction = ParameterDirection.Input;
    SqlParameter param2 = new SqlParameter("@count", 0);
    param2.Direction = ParameterDirection.Output;
    command.Parameters.Add(param1);
    command.Parameters.Add(param2);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = command;
    DataTable table = new DataTable("Customers");
    adapter.Fill(table);
    this.dataGridView1.AutoGenerateColumns = true;
    this.dataGridView1.DataSource = table;
    MessageBox.Show(command.Parameters[1].Value.ToString());
    connection.Close();
      

  3.   

    4楼的基本给出了,主要是设置参数的输出类型为 ParameterDirection.Output,获取列表的方法声明一个out参数即可
      

  4.   

    但是我这样写了以后只有下面的那个结果集,没有需要output的值啊
      

  5.   

    ...
    objParams[X] = new SqlParameter("@Id", SqlDbType.Int);
    objParams[X].Direction = ParameterDirection.Output;
    SqlHelper.ExecuteNonQuery(...);
    int result = (int)objParams[X].Value;
    ...
    ==============================
    result即是你要的output值,参数类型根据你自己的来!
      

  6.   

    但这样就获取不到下面那个select结果集了吧