日期:2014-05-18  浏览次数:20911 次

C#调用ORACLE包中的存储过程报错
过程定议:
  PROCEDURE P_LOGI(iv_userid IN VARCHAR,iv_password IN VARCHAR,
  ov_username OUT VARCHAR,ov_role OUT VARCHAR)
  IS
  r_zy JC_ZHIYDOC%ROWTYPE;
  BEGIN
  BEGIN
  SELECT * INTO r_zy
  FROM JC_ZHIYDOC
  WHERE ZHIY_NO=Upper(iv_userid);
  EXCEPTION WHEN OTHERS THEN
  PRC_UTL_RAISE(-20011,'WXW.P_LOGI','HDL001','@USER='||iv_userid||';');
  END;

  IF r_zy.PWD IS NULL THEN
  PRC_UTL_RAISE(-20011,'WXW.P_LOGI','HDL003','');
  END IF;

 /* \* IF Upper(iv_password)<>F_DECRYPT_DATA(r_zy.PWD) THEN
  PRC_UTL_RAISE(-20011,'PKG_UTL_LOGIN.P_LOGIN','HDL002','');*\
  END IF;*/

  ov_username := r_zy.ZHIY_NAME;
  ov_role := r_zy.JIAOS_ID;
  END P_LOGI;


C#前台调用:
 private void button1_Click(object sender, EventArgs e)
  {
  //声明变量
  string iv_userid = "";
  string iv_password = "";
  string ov_username = "";
  string ov_role = "";

  OracleConnection ORCNET = new OracleConnection("data source=lmis6;user id=Lmis;password=lmis6xj");
  OracleCommand cmd = new OracleCommand("WXW.P_LOGI", ORCNET);
  cmd.CommandType = CommandType.StoredProcedure;
  OracleParameter[] parm = new OracleParameter[4];
  //in
  parm[0] = new OracleParameter(@iv_userid, OracleType.VarChar, 10);
  parm[1] = new OracleParameter(@iv_password, OracleType.VarChar, 32);
  //out
  parm[2] = new OracleParameter(@ov_username, OracleType.VarChar, 50);
  parm[3] = new OracleParameter(@ov_role, OracleType.VarChar, 50);
  //设置参数输入输出类型
  parm[0].Direction=ParameterDirection.Input;
  parm[1].Direction=ParameterDirection.Input;
  parm[2].Direction=ParameterDirection.Output;
  parm[3].Direction=ParameterDirection.Output;
  //设置参数值类型
  parm[0].DbType = DbType.String;
  parm[1].DbType = DbType.String;
  parm[2].DbType = DbType.String;
  parm[3].DbType = DbType.String;
  //给参数赋值
  parm[0].Value = name.Text;
  parm[1].Value = pwd.Text;
  parm[2].Value = null;
  parm[3].Value = null;
  if (name.Text.Trim() == "" || pwd.Text.Trim() == "")
  {
  MessageBox.Show("用户名或密码不能为空!");
  }
  cmd.Parameters.Add(parm[0]);
  cmd.Parameters.Add(parm[1]);
  cmd.Parameters.Add(parm[2]);
  cmd.Parameters.Add(parm[3]);
  try
  {
  ORCNET.Open();
  cmd.ExecuteNonQuery();
  MessageBox.Show("成功连接ORACLE数据库");
  //ORCNET.Close();
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  }
  finally
  { 

  }
  }

------解决方案--------------------
注意对应参数的类型。