ASP script

Discussion in 'C#' started by jhodgso4, Oct 15, 2010.

  1. #1
    Hi
    we have just adopted a website and we cant get a part of it working and wondered if someone could point us in the right direction below; the error we are recieving is below and then the script causing it;

    Error
    Microsoft Cursor Engine error '80040e38'

    Row cannot be located for updating. Some values may have been changed since it was last read.

    /database/database.asp, line 112

    Function editRow(tableName, searchString) '#--- UPDATES AN EXISTING DATABASE ROW

    '#--- SET UP RECORDSET FOR EDITING A RECORD
    Set recordSet = Server.CreateObject("ADODB.RecordSet")
    recordSet.CursorLocation = 3
    recordSet.CursorType = adOpenForwardOnly
    recordSet.LockType = adLockOptimistic

    searchString = "SELECT * FROM " & tableName & " WHERE " & searchString
    If showSQL Then Response.Write "searchString: " & searchString & "<br><br>"
    recordSet.Open searchString, connection, , ,adCmdText

    '#--- ITERATE THROUGH rowParameters TO UPDATE ITEM'S FIELDS
    Dim rowField
    For Each rowField In tableFields
    If showSQL Then Response.Write rowField & ": " & tableFields.Item(rowField) & "<br>"
    recordSet(rowField) = tableFields.Item(rowField)
    Next

    '#--- UPDATE RECORDSET (UPDATE RECORD)

    recordSet.Update
    Set tableFields = CreateObject("Scripting.Dictionary")

    End Function

    This is the file that is calling the function:

    <!-- #include virtual="/admin/declarations.asp" -->
    <%
    Dim tableName
    tableName = "hrforumpages"
    Dim newItem
    newItem = True
    If Trim(Request.QueryString("delete")) <> "" Then
    openConnection
    connection.Execute("DELETE FROM hrforumbullet WHERE id=" & Trim(Request.QueryString("delete")) & "")
    End If
    If Trim(Request.QueryString("id")) <> "" Then
    newItem = False
    openConnection
    getResults "SELECT * FROM " & tableName & " WHERE id=" & Trim(Request.QueryString("id")), 1, 1
    Dim storebtmTxt, storebtmID
    storebtmTxt = getItem("nameofhrforum")
    storebtmID = getItem("id")

    End If

    if lcase(request.ServerVariables("REQUEST_METHOD"))="post" then
    openConnection


    If Request.Form("id") = "" Then newItem = True Else newItem = False

    '\--- ADD FIELDS

    addField "nameofhrforum", Request.Form("nameofhrforum")
    addField "bottomhrtext", Request.Form("bottomhrtext")

    '#--- IF 'SAVE AS NEW' OPTION HAS BEEN SELECTED, THEN ADD THIS ITEM TO THE DATABASE (A NEW ROW)
    If Request.Form("saveAsNew") <> "0" Or newItem Then
    addRow tableName
    Else
    '#--- OTHERWISE, UPDATE THE EXISTING ITEM
    editRow tableName, "id=" & Int(Request.Form("id"))
    Dim x

    Dim bulletArray
    '** Get the bullet information and update the existing items
    '** Loop through form items on the page
    For x = 1 to Request.Form.Count
    Dim bullet
    Dim formField
    Dim bulletID
    formField = Request.Form.Key(x)
    '** Get Only the bullet data and put into delimetered string
    If Instr(formField, "blTitle_") > 0 Then
    bulletID = Mid(formField, 9)
    Dim string1
    If bulletID > 0 Then
    string1 = bulletID & "|" & Request.Form.Item(x)
    End If
    End If
    If instr(formField, "blName_") > 0 Then
    Dim bid
    bid = Mid(formField, 8)
    If bid = bulletID Then
    Dim string2
    string2 = "|" & Request.Form.Item(x)
    End if
    End If
    If instr(formField, "date_") > 0 Then
    Dim bidd
    bidd = Mid(formField, 6)
    If bidd = bulletID Then
    Dim string3
    string3 = "|" & Request.Form.Item(x) & "|" & " *END* "
    bullet = string1 & string2 & string3
    bulletArray = bulletArray & bullet
    End If
    End If

    Next

    Dim i
    bulletArray = Split(bulletArray, " *END* ")
    '** Get the individual lines
    For i = 0 to Ubound(bulletArray)
    Dim newsBullet, y
    Dim title, descriptiveText, dateOfEvent, newsBulletID
    newsBullet = bulletArray(i)
    '** Split the string
    Dim newsItem
    newsItem = Split(newsBullet, "|")
    For y = 0 to Ubound(newsItem)
    select case y
    case 0
    newsBulletID = newsItem(y)
    case 1
    title = newsItem(y)
    case 2
    descriptiveText = newsItem(y)
    case 3
    dateOfEvent = newsItem(y)
    end select
    Next
    '* Update the database with bullets
    addField "bullet", descriptiveText
    addField "bulletTitle", title
    If dateOfEvent <> "" Then
    addField "eventDate", dateOfEvent
    addField "HasEventDate", 1
    Else
    addField "eventDate", Now()
    addField "HasEventDate", 0
    End If
    editRow "hrforumbullet", "id=" & newsBulletID
    Next

    '** Check to see if new bullet has been added
    If Request.Form("blTitleNew") <> "" Then
    addField "bulletTitle", Request.Form("blTitleNew")
    addField "bullet", Request.Form("blNameNew")
    addField "hrforumpage", Int(Request.Form("id"))
    addField "eventDate", Request.Form("dateNew")
    addField "HasEventDate", 1
    addRow "hrforumbullet"
    End If

    End If
    closeConnection
    Response.Write "<script language=""JavaScript"">" & vbCrLf
    Response.Write "opener.top.location.reload();" & vbCrLf
    Response.Write "window.close();" & vbCrLf
    Response.Write "</script>" & vbCrLf


    End If
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>
    <% If getItem("id") = "" Then Response.Write "Add" Else Response.Write "Edit" %>
    HR forum</title>
    <link href="/admin/styles.css" rel="stylesheet" type="text/css">

    <script language="javaScript" src="/includes/ajax.js"></script>

    <script language="javascript" src="/includes/functions.js"></script>

    <script language="javascript" src="/admin/functions.js"></script>

    <script language="javascript" src="/includes/validation.js"></script>

    <script language="javascript">
    function submitForm()
    {
    validate(document.popup.nameofhrforum.value != '', 'Please enter a name for your list', document.popup.nameofhrforum);
    //validate(document.popup.bottomhrtext.value != '', 'Please enter text', document.popup.bottomhrtext);
    //validate(isDate(document.popup.dateNew.value), 'Please enter a valid date for this article', document.popup.dateNew);
    var counter;

    if ( document.URL.indexOf("id=") > 0 )
    {
    var formElements = document.popup.elements;

    var proceed;
    for (i=0; i<formElements.length; i++) {

    var elementName;
    elementName = formElements.name;
    if ( elementName.match("date_"))
    {
    if ( formElements.value != "" )
    {
    validate(isDate(formElements.value), 'Please enter a valid date', formElements.value);
    }
    }

    }
    }
    if (allOK())
    {
    document.popup.submit();
    return true;
    }
    else
    {
    return false;
    }
    }

    function confirmation(deleteURL) {
    var answer = confirm("Delete Forum Item?")
    if (answer){
    newURL = deleteURL;
    window.location = newURL;
    }
    }
    </script>
    </head>
    <body id="greyBack">
    <div id="greenPopupBar">
    <div>
    <% If getItem("id") = "" Then Response.Write "Add" Else Response.Write "Edit" %>
    HR Forum Timetable</div>
    </div>
    <div id="greyPopupBar">
    <div>
    Change the details of this timetable and click on save</div>
    </div>
    <div id="popupBodyArea">
    <div id="popupBodyBox">
    <div style="height: 25px">
    </div>
    <form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post" name="popup" onsubmit="return submitForm();">
    <input type="hidden" name="id" value="<%= getItem("id") %>">
    <input type="hidden" name="saveAsNew" value="0">
    <div class="sectionTop">
    <div class="sectionTitle">
    HR Forum Timetable Name</div>
    <div class="topInstruction">
    Please enter the name of your timetable e.g. Summer 2009<br>
    </div>
    <div>
    <table align="center" border="0" cellspacing="2" cellpadding="0">
    <tr>
    <td class="fieldLabel" style="padding-right: 0px" valign="top">
    Name of Timetable:
    </td>
    <td class="field" valign="bottom">
    <input name="nameofhrforum" type="text" id="nameofhrforum" value="<%= getItem("nameofhrforum") %>">
    </td>
    </tr>
    </table>
    </div>
    <div class="sectionBottom">
    </div>
    </div>
    <div class="sectionTop">
    <div class="sectionTitle">
    Text at the bottom of the HR Bullets
    </div>
    <div>
    <table align="center" border="0" cellspacing="2" cellpadding="0">
    <tr>
    <td class="fieldLabel" style="padding-right: 0px" valign="top">
    </td>
    <td class="field" valign="bottom">
    <textarea name="bottomhrtext" id="bottomhrtext" style="width: 400px"><%= getItem("bottomhrtext") %></textarea>
    </td>
    </tr>
    </table>
    </div>
    <div class="sectionBottom">
    </div>
    </div>
    <% If not IsEmpty(Request.QueryString("id")) Then %>
    <div class="sectionTop" >
    <div class="sectionTitle">
    Forum Dates
    </div>
    <div>
    <table align="center" border="0" cellspacing="2" cellpadding="0" >
    <tr>
    <td class="fieldLabel" style="padding-right: 0px" valign="top"></td>
    <td class="field" valign="bottom">
    <table align="center" border="0" cellspacing="2" cellpadding="0">
    <tr>
    <td>Name:</td>
    <td>Description:</td>
    <td>Date e.g. 12/5/2010</td>
    </tr>
    <tr style="width:100%;">
    </tr>
    <tr>
    &nbsp;
    </tr>
    <%

    '** GET THE FORUM BULLETS WHICH CAN BE EVENTS ******
    set rs=Server.CreateObject("ADODB.recordset")
    Dim sql, rs
    sql = "Select * From hrforumbullet where hrforumpage = " & Trim(Request.QueryString("id"))
    rs.Open sql, connection
    Do while not rs.EOF
    %>

    <tr>
    <td class="fieldLabel" valign="top"><input name="blTitle_<%=rs("id")%>" id="blTitle_<%=rs("id")%>" value="<%= replace(rs("bulletTitle"),"<br>","")%>" /> </td>
    <td class="field" valign="top">
    <textarea name="blName_<%= rs("id") %>" id="blName_<%= rs("id") %>"><%=rs("bullet") %></textarea>
    <%
    Dim deleteUrl
    deleteUrl = Request.ServerVariables("SCRIPT_NAME") & "?delete=" & rs("id") & "&id=" & Trim(Request.QueryString("id"))
    %>
    </td>
    <td class="field" valign="top">
    <input name="date_<%= rs("id") %>" type="text" id="date_<%= rs("id") %>" value="<%If rs("HasEventDate") = 1 Then response.write Day(rs("EventDate")) & "/" & Month(rs("EventDate")) & "/" & Year(rs("EventDate")) End If%>" maxlength="95">
    </td>
    <td valign="top"><!--a href="javascript:confirmation('<'%= deleteURL %>');">
    <img id="deleteBullets" src="/admin/images/buttons/cross.gif" border="0"></a--></td>
    </tr>
    <%
    rs.MoveNext()
    Loop
    rs.close
    Set rs = nothing
    %>
    <!-- New Bullet Item -->
    <tr>
    <td class="fieldLabel" valign="top"><input name="blTitleNew" id="blTitleNew" value="" /> </td>
    <td class="field" valign="top">
    <textarea name="blNameNew" id="blNameNew"></textarea>
    </td>
    <td class="field" valign="top">
    <input name="dateNew" type="text" id="dateNew" value="" maxlength="95">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>
    <div class="sectionBottom">
    </div>
    <% End If %>
    </div>
    </div>
    </div>
    <div id="bottomPopupBar">
    <table cellpadding="0" cellspacing="10" border="0" align="center">
    <tr>
    <td class="popupButton">
    <a href="javascript:void submitForm();">Save</a>
    </td>
    <td class="popupButton">
    <a href="javascript:window.close();">Cancel</a>
    </td>
    </tr>
    </table>
    </div>
    </form>
    </body>
    </html>
     
    jhodgso4, Oct 15, 2010 IP