output参数也要传给存储过程带输入输出参数的存储过程create procedure itemCodes@itemName1 varchar(50),@sizeName1 varchar(50),@itemCode varchar(5) outputasselect @itemCode=itemmap.ItemCode from itemmap inner join item on itemmap.ItemCode=item.ItemCode where(item.ItemName1=@itemName1 and item.SizeName1=@sizeName1)go
static void ExecuteProcedure(string StrConn)        {            string strConn =strConn;            SqlConnection conn = new SqlConnection(strConn);            conn.Open();            SqlCommand cmd = new SqlCommand("getItemCode", conn);            cmd.CommandType = CommandType.StoredProcedure;            SqlParameter[] parameters =            {                new SqlParameter("@itemName1",SqlDbType.VarChar,50),                new SqlParameter("@sizeName1",SqlDbType.VarChar,50),                new SqlParameter("@itemCode",SqlDbType.VarChar,50)            };            parameters[0].Value = "Chai";            parameters[1].Value = "500g";            parameters[2].Direction = ParameterDirection.Output;            foreach (var p in parameters)            {                cmd.Parameters.Add(p);            }            cmd.ExecuteNonQuery();            conn.Close();            //输出值            Console.WriteLine(parameters[2].Value);        }

解决方案 »

  1.   

    程序中调用output存储过程static void ExecuteProcedure(string StrConn)        {            string strConn =StrConn;            SqlConnection conn = new SqlConnection(strConn);            conn.Open();            SqlCommand cmd = new SqlCommand("getItemCode", conn);            cmd.CommandType = CommandType.StoredProcedure;            SqlParameter[] parameters =            {                new SqlParameter("@itemName1",SqlDbType.VarChar,50),                new SqlParameter("@sizeName1",SqlDbType.VarChar,50),                new SqlParameter("@itemCode",SqlDbType.VarChar,50)            };            parameters[0].Value = "Chai";            parameters[1].Value = "500g";            parameters[2].Direction = ParameterDirection.Output;            foreach (var p in parameters)            {                cmd.Parameters.Add(p);            }            cmd.ExecuteNonQuery();            conn.Close();            //输出值            Console.WriteLine(parameters[2].Value);        }
      

  2.   

    我一般都是用SqlHelper来调用存储过程的。具体怎么写不知道。你在SqlServer中执行下存储过程,看看要什么参数
      

  3.   

    @JG_DM      char(4) output, 
      @JG_XX      char(60)output 
    这两个值在数据层也要进行赋值的。 parameters[“你的参数名称”].Direction = ParameterDirection.Output;