Results 1 to 2 of 2

Thread: Help with IF-problem

  1. #1

    Thread Starter
    Member shamloo's Avatar
    Join Date
    Oct 2000
    Location
    Stockholm, Sweden
    Posts
    32

    Question

    Hi, I am making a kind-of admin-site for a site and haven't dealt with asp much before.
    My problem:
    First of all, this is how Im thinking:
    ------------------
    *if the names from the form is NOT empty, do the following:
    **if the first-name and the last-name from the form exists in the database Response.write:
    That person is already added.
    **if the names do NOT match the one in the database, add the person and his/her info in the database and response.write:
    You have successfully added (the person)
    **if the name-fileds were empty, response.write:
    you forgot to fill in the name, please try again.
    ------------------
    What's not working is if I try to add a person that already is in the database it creates a new
    line in it with the info, and I do not want that to happen.
    Code:
    <!-- #include file="../db/adovbs.inc" -->
    <HTML>
    <HEAD>
    <TITLE>Untitled</TITLE>
    <LINK REL="STYLESHEET" TYPE="text/css" HREF="rstr.css"></STYLE>
    </HEAD>
    
    <BODY BGCOLOR="#ffffff">
    <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="2">
    <TR>
    <TD CLASS="Heading" COLSPAN="7">
    <%
    Set Connect = Server.CreateObject("ADODB.Connection") 
    Connect.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("../db/roster.mdb") 
    Set RS = Server.CreateObject("ADODB.Recordset") 
    Addera = "SELECT * FROM teamROSTER" 
    RS.Open Addera, Connect, adOpenStatic, adLockOptimistic 
    Dim fNamn,eNamn,JerseyNr,Pos,height,weight,born,city
    
    fNamn = Request.Form("fNamn")
    eNamn = Request.Form("eNamn")
    JerseyNr = Request.Form("Nr")
    Pos = Request.Form("pos")
    height = Request.Form("height")
    weight = Request.Form("weight")
    born = Request.Form("born")
    city = Request.Form("city")
    
    IF fNamn <>"" AND eNamn <>"" THEN
    DO UNTIL RS.EOF
    IF fNamn = RS("fNamn") AND eNamn = RS("eNamn") THEN
    Response.write("<B>" & fNamn &" " & eNamn & "</B> is allready in the teamROSTER<BR></TD>")
    EXIT DO
    ELSEIF fNamn <> RS("fNamn") AND eNamn <> RS("eNamn") THEN
    RS.AddNewRS("fNamn") = fNamn
    RS("eNamn") = eNamn
    RS("JerseyNr") = Jersey
    NrRS("pos") = Pos
    RS("Height") = Height
    RS("Weight") = Weight
    RS("Born") = Born
    RS("Birthplace") = City
    Response.write(RS("fNamn") & " " & RS("enamn") & " has been added to the teamROSTER<BR><BR></TD>")
    EXIT DO
    ELSE Response.write("")
    END IF
    RS.MoveNextLoop
    ELSEIF fNamn = "" AND eNamn="" THEN
    Response.write("You must fill in at least the players First and Last name<BR></TD>")
    ELSE
    Response.write("</TD>")
    END IF
    %>
    
    </TR>
    <TR>
    <TD CLASS="TD1"><A HREF="teamROSTER.asp">View teamROSTER</A><BR></TD>
    </TR>
    </TABLE>
    <%
    RS.Update
    RS.Close
    Connect.Close
    %>
    </BODY></HTML>
    This is the error-message I'm getting:
    Error Type:
    Provider (0x80020005)
    Type mismatch.
    /rstr/teamROSTER_added.asp, line 41

    And that shows that one of the IF's does not work, it tries to add the person despite he/she already is in the db.
    I'm getting that error-message cause I, on purpose, left a field blank.
    Even though that field is empty that part of the code should NOT be executed.

    does anyone of you see something wrong in the code above ??

    I really need help with this, I've stared my self almost blind on this problem for hours...

    thanks,
    David
    "There are no must's in life unless you provide for someone else than yourself"

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    For starters, you can't addnew to a static recordset. You will need to open it using either adOpenKeySet or adOpenDynamic.

    Also, if you cut and pasted the code directly, look at your RS.AddNew line.. it has the next line on the same line. Same thing for your RS.MoveNext line. (If you typed it then it's probably just a typo- no big deal)

    Make sure you are setting RS and Connect to Nothing at the bottom of your page.

    Don't enclose your arguments for Response.Write in parenthesis unless it's returning something (which it's not)

    This:
    Code:
    ELSEIF fNamn <> RS("fNamn") AND eNamn <> RS("eNamn") THEN
    RS.AddNewRS("fNamn") = fNamn
    RS("eNamn") = eNamn
    RS("JerseyNr") = Jersey
    NrRS("pos") = Pos
    RS("Height") = Height
    RS("Weight") = Weight
    RS("Born") = Born
    RS("Birthplace") = City
    Response.write(RS("fNamn") & " " & RS("enamn") & " has been added to the teamROSTER<BR><BR></TD>")
    EXIT DO
    ELSE Response.write("")
    END IF
    Should just be this:
    Code:
    ELSE
        RS.AddNew
        RS("fNamn") = fNamn
        RS("eNamn") = eNamn
        RS("JerseyNr") = JerseyNr
        RS("pos") = Pos
        RS("Height") = Height
        RS("Weight") = Weight
        RS("Born") = Born
        RS("Birthplace") = City
        Response.write(RS("fNamn") & " " & RS("enamn") & " has been added to the teamROSTER<BR><BR></TD>")
        EXIT DO
    END IF
    Since you are declaring your variables (which you should be), your object variables (Connect and RS) should also be declared, and while you don't HAVE to, you should declare them at the top rather than inside the code.

    That's about all I can think of for now..
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

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



Click Here to Expand Forum to Full Width