首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请一上这个函数为什么总出错

2012-11-13 
请高手指点一下这个函数为什么总出错public static int KeyIfExists(string strKey,string strVal){int re

请高手指点一下这个函数为什么总出错
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();
  }
  }

[解决办法]
@Class这个参数没有Add啊
得象前面一样先Add了来

热点排行