public static int KeyIfExists(string strKey,string strVal)
        {
            int retVal = 0;
            DBOperation db=new DBOperation();
            SqlConnection con=db.CreateCon();
            try
            {   
                con.Open();
                SqlCommand cmd=new SqlCommand("KeyIfExists",con);
                cmd.CommandType=CommandType.StoredProcedure;
                cmd.Parameters.Add("@Tag", SqlDbType.Int).Value = 1;
                cmd.Parameters.Add("@Key", SqlDbType.VarChar).Value = strKey;
                cmd.Parameters.Add("@Val", SqlDbType.VarChar).Value =strVal;
                SqlParameter OutValue = cmd.Parameters.Add("@RetValue", SqlDbType.Int);
                OutValue.Direction = ParameterDirection.Output;
                cmd.Parameters["@Class"].Value = 1;//执行到这儿就出错了。
                cmd.ExecuteReader();
                int outVal = (int)OutValue.Value;
                if (outVal == 0)
                    retVal=0;
                else
                    retVal=1;
                return retVal;
            }
            catch (System.Exception )
            {
                throw;
            }
            finally
            {
                con.Close();
            }
        }

解决方案 »

  1.   

    @Class这个参数没有Add啊
    得象前面一样先Add了来
      

  2.   

    如果你存储过程还有返回select结果集的话。还得执行一下sqlDataReader.NextResult()方法才能得到output值
      

  3.   

    catch (System.Exception )
    =>
    catch (System.Exception ex)
    {
        MessageBox.Show(ex.Message); //看看出什么错
    }
      

  4.   

    catch (System.Exception ex)
      {
      //断点,看ex.message
      }