如题,做一个页面,是插入学生信息的,调用oracle的存储过程,产生了主键重复的异常,那么在asp.net里该怎么捕获这个异常,提示给用户呢。

解决方案 »

  1.   

    和sql的提示是一样的呀~~~,只是异常信息不一样~~~
      

  2.   

    我想做一个页面,功能是课程表中插入新的课程记录,但是有可能插入时会出现主键重复,所以我在oracle的存储过程里有异常捕捉代码,捕捉到异常后插入信息到日志表。就下面这个存储过程。
    差生异常的时候是能插入日志表,但在ASP.NET页面我捕获不到异常了。我想问的就是怎么样让Oracle处理了异常且ASP.NET页面也能捕获异常提示用户    procedure prc_course(id in course.cno%type,names in course.cname%type,credits in course.credit%type,operation in varchar2)
      is
       PK_conflict Exception;  --定义异常
       pragma  Exception_init(PK_conflict,-1);  
      begin
       if operation='insert' then --插入课程记录
          insert into course(cno,cname,credit) values(id,names,credits);
        elsif  operation='delete' then --删除课程记录
          delete from course where id=course.cno;
        elsif  operation='update' then  --更新课程记录
          update course set course.cname=names,course.credit=credits where cno=id;
        end if;
        Exception
        when PK_conflict then   --处理异常
         insert into log values(seq_log_id.nextval,'LOG','Insert error','',sysdate,user);
         try
            {
                oleConn.Open();
                cmd.ExecuteNonQuery();
                oleConn.Close();
                this.Bind();
            }
            catch (OleDbException e)
            {
                Response.Write("<script>alert('发生异常,请检查输入后再提交')</script>");
            }