Error handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Kowaluk

    Error handling

    I have an intranet site that connects to an access database using ASP
    (Javascript).[color=blue]
    > Currently, when an user attempts to enter a duplicate value into the
    > database it is rejected and the user is redirected to a custom
    > message generated by the ODBC driver (I think). How can I change this so
    > that the user is redirected to a message that I customise myself?[/color]



  • Tim Williams

    #2
    Re: Error handling

    Change the code so it does what you want.

    Post the relevant code if you really want help.

    tim

    "Andy Kowaluk" <akowaluk@optus net.com.au> wrote in message
    news:3f10dd80$0 $26536$afc38c87 @news.optusnet. com.au...[color=blue]
    > I have an intranet site that connects to an access database using ASP
    > (Javascript).[color=green]
    > > Currently, when an user attempts to enter a duplicate value into the
    > > database it is rejected and the user is redirected to a custom
    > > message generated by the ODBC driver (I think). How can I change this so
    > > that the user is redirected to a message that I customise myself?[/color]
    >
    >
    >[/color]


    Comment

    • Andy Kowaluk

      #3
      Re: Error handling

      OK, here goes.

      I am new to coding in Javascript. The page was created in Dreamweaver. Here
      is the code. If you can help I would be grateful.

      Andy



      <%@LANGUAGE="JA VASCRIPT" CODEPAGE="1252" %>
      <!--#include file="Connectio ns/connBooking.asp " -->
      <%

      // *** Edit Operations: declare variables

      // set the form action variable
      var MM_editAction = Request.ServerV ariables("SCRIP T_NAME");
      if (Request.QueryS tring) {
      MM_editAction += "?" + Request.QuerySt ring;
      }

      // boolean to abort record edit
      var MM_abortEdit = false;

      // query string to execute
      var MM_editQuery = "";
      %>
      <%
      // *** Insert Record: set variables

      if (String(Request ("MM_insert" )) == "frbook") {

      var MM_editConnecti on = MM_connBooking_ STRING;
      var MM_editTable = "Bookings";
      var MM_editRedirect Url = "confirmation.h tm";
      var MM_fieldsStr =
      "mnWeekBook|val ue|mnDayBook|va lue|mnPeriodBoo k|value|mnResou rceBook|value|m n
      UserBook|value" ;
      var MM_columnsStr =
      "WeekendingId|' ,none,''|Day|', none,''|Period| ',none,''|Resou rce|',none,''|U s
      ername|',none,' '";

      // create the MM_fields and MM_columns arrays
      var MM_fields = MM_fieldsStr.sp lit("|");
      var MM_columns = MM_columnsStr.s plit("|");

      // set the form values
      for (var i=0; i+1 < MM_fields.lengt h; i+=2) {
      MM_fields[i+1] = String(Request. Form(MM_fields[i]));
      }

      // append the query string to the redirect URL
      if (MM_editRedirec tUrl && Request.QuerySt ring && Request.QuerySt ring.Count[color=blue]
      > 0) {[/color]
      MM_editRedirect Url += ((MM_editRedire ctUrl.indexOf(' ?') == -1)?"?":"&")
      + Request.QuerySt ring;
      }
      }
      %>
      <%
      // *** Insert Record: construct a sql insert statement and execute it

      if (String(Request ("MM_insert" )) != "undefined" ) {

      // create the sql insert statement
      var MM_tableValues = "", MM_dbValues = "";
      for (var i=0; i+1 < MM_fields.lengt h; i+=2) {
      var formVal = MM_fields[i+1];
      var MM_typesArray = MM_columns[i+1].split(",");
      var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
      var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
      var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
      if (formVal == "" || formVal == "undefined" ) {
      formVal = emptyVal;
      } else {
      if (altVal != "") {
      formVal = altVal;
      } else if (delim == "'") { // escape quotes
      formVal = "'" + formVal.replace (/'/g,"''") + "'";
      } else {
      formVal = delim + formVal + delim;
      }
      }
      MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
      MM_dbValues += ((i != 0) ? "," : "") + formVal;
      }
      MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ")
      values (" + MM_dbValues + ")";

      if (!MM_abortEdit) {
      // execute the insert
      var MM_editCmd = Server.CreateOb ject('ADODB.Com mand');
      MM_editCmd.Acti veConnection = MM_editConnecti on;
      MM_editCmd.Comm andText = MM_editQuery;
      MM_editCmd.Exec ute();
      MM_editCmd.Acti veConnection.Cl ose();

      if (MM_editRedirec tUrl) {
      Response.Redire ct(MM_editRedir ectUrl);
      }
      }

      }
      %>
      <%
      var reWeekBook__MMC olParam = "False";
      if (String(Request ("MM_EmptyValue ")) != "undefined" &&
      String(Request( "MM_EmptyValue" )) != "") {
      reWeekBook__MMC olParam = String(Request( "MM_EmptyValue" ));
      }
      %>
      <%
      var reWeekBook = Server.CreateOb ject("ADODB.Rec ordset");
      reWeekBook.Acti veConnection = MM_connBooking_ STRING;
      reWeekBook.Sour ce = "SELECT WeekendingID FROM Weeks WHERE Completed = "+
      reWeekBook__MMC olParam.replace (/'/g, "''") + " ORDER BY WeekNo ASC";
      reWeekBook.Curs orType = 0;
      reWeekBook.Curs orLocation = 2;
      reWeekBook.Lock Type = 1;
      reWeekBook.Open ();
      var reWeekBook_numR ows = 0;
      %>
      <%
      var reResourcesBook = Server.CreateOb ject("ADODB.Rec ordset");
      reResourcesBook .ActiveConnecti on = MM_connBooking_ STRING;
      reResourcesBook .Source = "SELECT Resource FROM Resources ORDER BY Sort ASC";
      reResourcesBook .CursorType = 0;
      reResourcesBook .CursorLocation = 2;
      reResourcesBook .LockType = 1;
      reResourcesBook .Open();
      var reResourcesBook _numRows = 0;
      %>
      <%
      var reUsersBook = Server.CreateOb ject("ADODB.Rec ordset");
      reUsersBook.Act iveConnection = MM_connBooking_ STRING;
      reUsersBook.Sou rce = "SELECT * FROM Users ORDER BY Sort ASC";
      reUsersBook.Cur sorType = 0;
      reUsersBook.Cur sorLocation = 2;
      reUsersBook.Loc kType = 1;
      reUsersBook.Ope n();
      var reUsersBook_num Rows = 0;
      %>

      <html>
      <head>
      <title>Resour ce Bookings</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style type="text/css">
      </style>
      <link href="Styles/Style.css" rel="stylesheet " type="text/css">
      </head>

      <body>
      <div id="Header"> Resource Booking Form</div>
      <div id="Content">

      <div id="TopMenu">|< a href="http://intranet"> Intranet Home</a> |<a
      href="default.a sp">
      Search Form</a> |<a href="bookings. asp"> Booking Form</a> |</div>
      <form action="<%=MM_e ditAction%>" method="POST" name="frbook" id="frbook">
      <table width="90%" border="0">
      <tr>
      <td width="25%"><st rong>Week Ending</strong></td>
      <td width="34%"><se lect name="mnWeekBoo k" id="mnWeekBook" >
      <%
      while (!reWeekBook.EO F) {
      %>
      <option
      value="<%=(reWe ekBook.Fields.I tem("Weekending ID").Value)%>"> <%=(reWeekBook. F
      ields.Item("Wee kendingID").Val ue)%></option>
      <%
      reWeekBook.Move Next();
      }
      if (reWeekBook.Cur sorType > 0) {
      if (!reWeekBook.BO F) reWeekBook.Move First();
      } else {
      reWeekBook.Requ ery();
      }
      %>
      </select> </td>
      <td width="45%" rowspan="7"><if rame width=174 height=189
      name="gToday:no rmal:agenda.js" id="gToday:norm al:agenda.js"
      src="iflateng.h tm"
      scrolling="no" frameborder="0" >
      <ilayer>
      <layer name="gToday:no rmal:agenda.js" src="nflateng.h tm"> </layer>
      </ilayer>
      </iframe> </td>
      </tr>
      <tr>
      <td><strong>Day </strong></td>
      <td><select name="mnDayBook " size="1" id="mnDayBook" >
      <option value="Monday" selected>Monday </option>
      <option value="Tuesday" >Tuesday</option>
      <option value="Wednesda y">Wednesday </option>
      <option value="Thursday ">Thursday</option>
      <option value="Friday"> Friday</option>
      </select> </td>
      </tr>
      <tr>
      <td><strong>Per iod</strong></td>
      <td><select name="mnPeriodB ook" size="1" id="mnPeriodBoo k">
      <option value="Period 1" selected>Period 1</option>
      <option value="Period 2">Period 2</option>
      <option value="Period 3">Period 3</option>
      <option value="Period 4">Period 4</option>
      <option value="Period 5">Period 5</option>
      <option value="Period 6">Period 6</option>
      </select></td>
      </tr>
      <tr>
      <td><strong>Res ources</strong></td>
      <td><select name="mnResourc eBook" id="mnResourceB ook">
      <%
      while (!reResourcesBo ok.EOF) {
      %>
      <option
      value="<%=(reRe sourcesBook.Fie lds.Item("Resou rce").Value)%>" ><%=(reResource s
      Book.Fields.Ite m("Resource").V alue)%></option>
      <%
      reResourcesBook .MoveNext();
      }
      if (reResourcesBoo k.CursorType > 0) {
      if (!reResourcesBo ok.BOF) reResourcesBook .MoveFirst();
      } else {
      reResourcesBook .Requery();
      }
      %>
      </select> </td>
      </tr>
      <tr>
      <td><strong>Use r</strong></td>
      <td> <select name="mnUserBoo k" id="mnUserBook" >
      <%
      while (!reUsersBook.E OF) {
      %>
      <option
      value="<%=(reUs ersBook.Fields. Item("Username" ).Value)%>"><%= (reUsersBook.Fi e
      lds.Item("Usern ame").Value)%> </option>
      <%
      reUsersBook.Mov eNext();
      }
      if (reUsersBook.Cu rsorType > 0) {
      if (!reUsersBook.B OF) reUsersBook.Mov eFirst();
      } else {
      reUsersBook.Req uery();
      }
      %>
      </select></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
      <tr>
      <td><input type="submit" name="Submit" value="Make Booking"></td>
      <td><input type="reset" name="Submit2" value="Reset"></td>
      </tr>
      </table>
      <input type="hidden" name="MM_insert " value="frbook">
      </form>

      </div>
      <div id="Footer">
      <div align="justify" >
      <strong>Instruc tions</strong> <br>
      To make a booking complete each of the fields and press the MAKE
      BOOKING
      button. Be sure to modify every field.
      </div>
      </div>


      </body>
      </html>
      <%
      reWeekBook.Clos e();
      %>
      <%
      reResourcesBook .Close();
      %>
      <%
      reUsersBook.Clo se();
      %>

      "Tim Williams" <saxifraxREMOVE @THISpacbell.ne t> wrote in message
      news:nq7Qa.2405 $IX7.947@newssv r16.news.prodig y.com...[color=blue]
      > Change the code so it does what you want.
      >
      > Post the relevant code if you really want help.
      >
      > tim
      >
      > "Andy Kowaluk" <akowaluk@optus net.com.au> wrote in message
      > news:3f10dd80$0 $26536$afc38c87 @news.optusnet. com.au...[color=green]
      > > I have an intranet site that connects to an access database using ASP
      > > (Javascript).[color=darkred]
      > > > Currently, when an user attempts to enter a duplicate value into the
      > > > database it is rejected and the user is redirected to a custom
      > > > message generated by the ODBC driver (I think). How can I change this[/color][/color][/color]
      so[color=blue][color=green][color=darkred]
      > > > that the user is redirected to a message that I customise myself?[/color]
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...