• Editing/Updating Access Database via ASP

    Home » Forums » Developers, developers, developers » Web design and development » Editing/Updating Access Database via ASP

    Author
    Topic
    #372169

    I have an Access database that I’m trying to edit/update via VBScript via 3 different ASP files.
    My problem is that although the scripts all seem to have the proper syntax, one works all of the time, one works for only some records, and one never works.

    Can anyone see any obvious errors that I’m making? Tech support at the web hosting company has tried, but can’t discover any problems.

    I don’t think that it’s a “rights” problem because one of the files edits the database.

    updatepassword.asp allows members to change their login password. This file always works.

    <%
    Dim SqlStmt
    Dim rst
    Dim c

    Set dbConn = Server.CreateObject("ADODB.Connection")
    dbConn.Open Application("Members_ConnectionString")

    If Session("vIDOK") = True then
    SqlStmt="SELECT * FROM tMembers "
    SqlStmt=SqlStmt & "WHERE LoginID = '" & Session("vID") & "' "
    Set rst = Server.CreateObject("ADODB.Recordset")
    rst.Open SqlStmt,dbconn,adOpenKeyset,adLockOptimistic

    rst.MoveFirst
    If (rst.BOF and rst.EOF) then
    response.redirect "/memberloginfail.htm"
    else
    rst("LoginPwd")=Request.Form("NewPwd")
    rst("LastChangeDate")=Date
    rst("LastChangeBy")=Session("vID")
    rst.Update
    response.redirect "/_scripts/memberhomepage.asp"
    End if
    Else
    response.redirect "/memberlogin.htm"
    End If

    rst.close
    set rst = Nothing

    dbConn.Close
    Set dbConn = Nothing

    updatemyrecord.asp allows members to change certain fields, such as phone number, address, etc. I haven’t been able to see any pattern as to why this file allows some records to be updated, but not others.

    enternewmember.asp lets the membership chairperson add new members to the database. This file doesn’t generate any error messages, but new records aren’t being added.

    <%
    Dim SqlStmt
    Dim rst
    Dim fld
    Dim Maxnum
    Dim NewID
    Dim NewPwd
    Dim RandomNum
    Dim CurMinute

    Set dbConn = Server.CreateObject("ADODB.Connection")
    dbConn.Open Application("Members_ConnectionString")

    SqlStmt="SELECT Max(MemberID) AS lastid FROM tMembers"
    Set rst = Server.CreateObject("ADODB.Recordset")
    rst.Open SqlStmt,dbconn

    Maxnum = rst("lastid").value
    Maxnum = cstr(Maxnum+1)
    NewID = "ABC" & Maxnum
    rst.Close
    set rst = Nothing

    randomize
    RandomNum = cstr(int(rnd * 999))
    RandomNum = Right("000" & RandomNum,3)
    CurMinute = minute(now)
    If CurMinute

    Viewing 1 reply thread
    Author
    Replies
    • #594016

      Does it make any difference if you change the CursorType from adOpenKeyset to adOpenDynamic? It may sound as though this would retrieve a boatload of records, but if you modulate the CacheSize property of the recordset, you probably can tune the performance sufficiently.

    • #594020

      A couple of thoughts…

      First – everything looks like well-written code. Kudos!

      Second – I see a couple of ADO issues that seem like they may be the problem (based on my limited, but ever-increasing experience).

      Basically, I believe you have to tell ADO to move to a certain record before you can edit a record – even if the recordset only returns 1 record…

      So, in your “updatemyrecord.asp” file, you’ll want to do a rst.MoveFirst right after your rst.Open…. line (before updating your records).

      Also, I usually don’t use the adCmdTable option in my rst.Open command. I don’t know if that has anything to do with it or not… I think the adCmdTable is meant to be used with SQL Server rather than Access, but I guess it wouldn’t hurt to try…

      I hope this helps

      • #596547

        I ‘think’ that I’ve narrowed the problem down to Null values on the input form.

        Although many of the database fields are not required, if I leave some of them blank on the form, the record isn’t updated. However, if I enter something into each field, I can update the record.

        Does this make sense?

        The current design of the database does not allow Zero Length Strings. Should I change this field setting?

        • #596549

          Yes – that can be an issue. I’m not sure what other developers do with this, but I usually set the Allow Zero Length Strings to True (even though the default is False). This makes things flow a bit easier when working with ADO/ASP.

          Of course, that all depends on your data validation needs. Leaving Allow Zero Length set to True is only recommended if you have either a non-required field or some sort of validation technique in place (either client or server side).

          Also, I don’t recall whether you’ve alred mentioned this in your previous posts, but you may want to try adding a few lines that help you isolate errors: Include a “On Error Resume Next” line before starting your recordset operaions (such as inserting or updating data) and a “If cnn.Errors.count > 0 Then… ” block after your recordset oprations. I usually dump all errors into a string that I always show in my document. If there are no errors, the string is invisible, otherwise, the user sees an error message with th error and description of the problem.

          Hope this helps!

          • #597297

            Changing the Allow Zero Length Strings setting to True seems to have corrected my updating problems.

            Thanks,

    Viewing 1 reply thread
    Reply To: Editing/Updating Access Database via ASP

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: