can't get my edit-form to work - querystring-problem ?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default can't get my edit-form to work - querystring-problem ?

    Hi !
    got another problem...can't seem to get enough of them =)
    i have a table in my database called 'Accounts', which contains a
    bunch of users, with ID, username, password etc. in my main admin-page
    menu, i klick 'edit user' and all users in the db-table are listed
    nicely in a table. i've made the 'Pnr' (the ID) a link so i can click
    it to choose which user to edit. so far so good...
    i then want the editUserForm to open up with the choosen users data in
    the form, so i can edit it and submit it to update the database.
    when i click on a user in the list i get the following error:

    Error Type:
    ADODB.Recordset (0x800A0CC1)
    Item cannot be found in the collection corresponding to the requested
    name or ordinal.
    /VS_Files/updateUserForm.asp, line 19

    i think i'm doing something wrong when i try to pass variables with a
    querystring...but i'm not sure...
    could really use some help...(this is all a part of my bachelors
    project)

    the code is included below.
    i got 3 files to do the job: chooseUserToEdit.asp, updateUserForm.asp
    & updateUser.asp

    THANKS A LOT EVERYBODY !!!
    ------------------------------------------------------------------------
    chooseUserToEdit.asp

    <!--#Include File="Connect.asp" -->

    <%
    Set RS = Server.CreateObject("ADODB.Recordset")
    RS.ActiveConnection = Con

    SQLstring = "SELECT Pnr, FirstName, LastName FROM Accounts"
    RS.Open SQLstring
    %>

    <html>
    <body bgcolor="">

    <center>
    <table width="500" border=1 bgcolor=""
    cellpadding="4" cellspacing="0">
    <tr>
    <td align="center" colspan="3" bgcolor="">
    <font face="Arial" size="3"><b>
    Choose user to edit
    </b></font>
    </td>
    </tr>
    <%
    'loop through all available users & display them
    WHILE NOT RS.EOF
    %>
    <tr>
    <!--passes a querystring to updateUserForm.asp
    matches href with right record -->

    <td width="100"><a href="updateUserForm.asp?pid=<%=RS("Pnr")%>">
    <%=RS("Pnr")%></a>
    </td>
    <td width="200"><%=RS("FirstName")%> </td>
    <td><%=RS("LastName")%> </td>
    </tr>
    <%
    RS.MoveNext
    WEND
    %>
    <%
    RS.Close
    Con.Close
    %>
    </table>
    </center>
    </body>
    </html>
    --------------------------------------------------------------------
    updateUserForm.asp

    <!--#Include File="Connect.asp" -->

    <%
    'Get the user Pnr from chooseUserToEdit.asp (throuh the
    querystring)

    Pnumber = Request.Querystring("pid")

    'Open the Recordset

    Set RS = Server.CreateObject("ADODB.Recordset")
    RS.ActiveConnection = Con

    SQLstring = "SELECT * FROM Accounts WHERE Pnr = " & "'" & Pnumber &
    "'"
    RS.Open SQLstring

    'store the record in local variables

    IF NOT RS.EOF THEN
    Pnr = RS(" Pnr ") //line 19
    FirstName = RS(" FirstName ")
    LastName = RS(" LastName ")
    UserName = RS(" UserName ")
    PassWord = RS(" PassWord ")
    UserType = RS(" UserType ")
    Company = RS(" Company ")
    END IF
    RS.Close

    %>

    <html>
    <head><title>Update User</title></head>
    <body bgcolor="">

    <form method="post" action="updateUser.asp">

    <center>
    <table width="600" border=1 bgcolor=""
    cellpadding="4" cellspacing="0">
    <tr>
    <td colspan="2" bgcolor="">
    <font face="Arial" size="3"><b>
    Edit User
    </b></font>
    </td>
    </tr>
    <tr>
    <td>
    <b> Pnr:</b>
    </td>
    <td>
    <input name="Pnr" type="text"
    size="20" maxlength="20"
    value = "<%=Server.HTMLEncode(Pnr)%>">
    </td>
    </tr>
    <tr>
    <td>
    <b>First name:</b>
    </td>
    <td>
    <input name="FirstName" size="20" type="text"
    value = "<%=Server.HTMLEncode(FirstName)%>">
    </td>
    </tr>
    <tr>
    <td>
    <b>Last name:</b>
    </td>
    <td>
    <input name="LastName" type="text"
    size="20"
    value = "<%=Server.HTMLEncode(LastName)%>">
    </td>
    </tr>
    <tr>
    <td>
    <b>User name:</b>
    </td>
    <td>
    <input name="UserName" type="text"
    size="20"
    value = "<%=Server.HTMLEncode(UserName)%>">
    </td>
    </tr>
    <tr>
    <td>
    <b>Password:</b>
    </td>
    <td>
    <input name="PassWord" type="text"
    size="20" maxlength="20"
    value = "<%=Server.HTMLEncode(PassWord)%>">
    </td>
    </tr>
    <tr>
    <td>
    <b>User type:</b>
    </td>
    <td>
    <input name="UserType" type="text"
    size="20" maxlength="20"
    value = "<%=Server.HTMLEncode(UserType)%>">
    </td>
    </tr>
    <tr>
    <td>
    <b>Company:</b>
    </td>
    <td>
    <input name="Company" type="text"
    size="20" maxlength="20"
    value = "<%=Server.HTMLEncode(Company)%>">
    </td>
    </tr>
    <tr>
    <td colspan=2 align="right">
    <input type="submit" value="Add User">
    </td>
    </tr>
    </table>
    </center>

    <input name="updateUser" type="hidden" value="1">
    </form>

    </body>
    </html>
    --------------------------------------------------------------------
    updateUser.asp

    <!--#Include File="Connect.asp" -->

    <%

    ' Get the Form Variables
    updateUser = TRIM( Request( "updateUser" ) )

    Pnr = TRIM( Request( "Pnr" ) )
    FirstName = TRIM( Request( "FirstName" ) )
    LastName = TRIM( Request( "LastName" ) )
    UserName = TRIM( Request( "UserName" ) )
    PassWord = TRIM( Request( "PassWord" ) )
    UserType = TRIM( Request( "UserType" ) )
    Company = TRIM( Request( "Company" ) )


    ' Assign Default Values
    IF Pnr = "" THEN
    Pnr = "???"
    END IF
    IF FirstName = "" THEN
    FirstName = "???"
    END IF
    IF LastName = "" THEN
    LastName = "???"
    END IF
    IF UserName = "" THEN
    UserName = "???"
    END IF
    IF PassWord = "" THEN
    PassWord = "???"
    END IF
    IF UserType = "" THEN
    UserType = "???"
    END IF
    IF Company = "" THEN
    Company = "???"
    END IF

    %>
    <html>
    <head><title>Update Users</title></head>
    <body bgcolor="gray">
    <%
    ' Update User
    IF updateUser <> "" THEN

    sqlString = "UPDATE Accounts SET Pnr = ' " & Pnr & "'," & "'" &
    FirstName & "'," &_
    "'" & LastName & "'," & "'" & UserName & "'," & "'" &
    PassWord & "'," &_
    "'" & UserType & "'," & "'" & Company & "'" &_
    "WHERE Pnr = " & "'" & Pnr & "'"


    Con.Execute sqlString
    %>
    <center>
    <table width="600" cellpadding="4"
    cellspacing="0" bgcolor="lightyellow">
    <tr>
    <td>
    <%=FirstName%> was updated in the database
    </td>
    </tr>
    </table>
    </center>
    <p>
    <%
    END IF
    %>

    <a href="updateUserForm.asp">Update User</a>

    </body>
    </html>
    ----------------------------------------------------------------------
    Fredrik/Sweden Guest

  2. Similar Questions and Discussions

    1. querystring parameter passing problem in a datagrid using hyperlink column
      I can not display the data retrieved from the database using querystring. My code here , I could not find the problem. void Page_Load(object...
    2. Add / edit on the same form?
      I am building a site with many many different record insert / update pages. I am interested in combining the 2 forms ( add / edit ) into 1 as I have...
    3. [ASP/VBscript] Preserve querystring in "get" form ?
      Maybe a stupid question, but how can I preserve an existing querystring when using the "get" method to process the form. When using "post" the...
    4. Confused about a REQUEST.FORM and a REQUEST.QUERYSTRING
      This is snipit of code, supplied by PayPal with explanation about what has to be done to access their back end. I am confused because they first...
    5. Edit button in datagrid doesn't work!?
      Hi, I have this piece of code: <asp:datagrid id="dgRezervirano" runat="server" CssClass="rezervacije" AutoGenerateColumns="false"...
  3. #2

    Default Re: can't get my edit-form to work - querystring-problem ?

    It seems my reply vanished, so if I'm double posting, sorry.

    Do you column names really have a space at the beginning and the end?

    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    news:a501fefe.0309301305.6f9b9167@posting.google.c om...
    > Item cannot be found in the collection corresponding to the requested
    > name or ordinal.
    > Pnr = RS(" Pnr ") //line 19

    Try RS("Pnr")
    Or better yet, RS.Fields.Item(0).Value

    Ray at home


    Ray at Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139