multiple insert problem !

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

  1. #1

    Default multiple insert problem !

    hi !
    had to come right back...
    this time i'm trying to do a multiple insert.
    in my admin website i want to add users to a specific project. i klick
    that option and all projects are listed nicely. i chose project, then
    i get all available users listed with a checkbox in front of each one.
    i check the boxes of the users i want to add to the project and then
    submit to insert them all into the database. this last step is causing
    a 'type mismatch', and i can't find it !

    i pass all checked boxes to the insert-file as a comma-delimited list.
    i knew then that i had to use the split-funktion to get the items into
    an array, and then loop the SQL statement to insert all of them. i'm
    not sure here, maybe i'm doing something wrong...
    The error message:

    Error Type:
    Microsoft VBScript runtime (0x800A000D)
    Type mismatch
    /VS_Files/insertAccountsProjects.asp, line 25

    code included below (as usual)...
    ---------------------------------------------------------------------------
    listAllProjects.asp
    <!--#Include File="Connect.asp" -->

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

    SQLstring = "SELECT ProjectID, ProjectName FROM Projects"
    RS.Open SQLstring
    %>

    <html>
    <body bgcolor="">

    <center>
    <table width="500" border=1 bgcolor=""
    cellpadding="4" cellspacing="0">
    <tr>
    <td align="center" colspan="2" bgcolor="">
    <font face="Arial" size="3"><b>
    Choose a Project
    </b></font>
    </td>
    </tr>

    <%
    'loop through all available Projects & display them

    WHILE NOT RS.EOF
    %>
    <tr>
    <!--passes a querystring to chooseUserToAddToProject.asp
    matches href with right record -->

    <td width="100"><a
    href="chooseUserToAddToProject.asp?PID=<%=RS("Proj ectID")%>">
    <%=RS("ProjectID")%></a>
    </td>
    <td width="200"><%=RS("ProjectName")%>
    </td>
    </tr>
    <%
    RS.MoveNext
    WEND
    %>

    <%
    RS.Close : Set RS = Nothing
    Con.Close : Set con = Nothing
    %>

    </table>

    <a href="admin.html">Back</a>

    </center>
    </body>
    </html>
    ---------------------------------------------------------------------
    chooseUserToAdToProject.asp
    <!--#Include File="Connect.asp" -->

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

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

    'Get the ProjectID from listAllProjects.asp (throuh the
    querystring)

    ProID = Request.Querystring("PID")
    %>

    <html>
    <body bgcolor="">

    <center>
    <FORM METHOD="POST" ACTION="insertAccountsProjects.asp">
    <table width="500" border="1" bgcolor="" cellpadding="4"
    cellspacing="0">
    <tr>
    <td align="center" colspan="4" bgcolor="">
    <font face="Arial" size="3"><b>
    Choose user to add to <%=ProID%>
    </b></font>
    </td>
    </tr>

    <%
    'loop through all available users & display them

    WHILE NOT RS.EOF
    %>
    <tr>
    <td width="30">
    <INPUT TYPE="CHECKBOX" NAME="check" VALUE=<%=RS("Pnr")%>>
    </td>
    <td width="90"><%=RS("Pnr")%> </td>
    <td width="150"><%=RS("FirstName")%> </td>
    <td><%=RS("LastName")%> </td>
    </tr>
    <%
    RS.MoveNext
    WEND

    RS.Close
    Con.Close
    %>
    <tr>
    <td colspan=4 align="right">
    <input type="submit" value="Add to project">
    </td>
    </tr>
    </table>
    <input type="hidden" name="pro" value="<%=ProID%>"> <!-- pass the
    project id to insert-file -->
    </FORM>
    <a href="admin.html">Back</a>
    </center>
    </body>
    </html>
    ---------------------------------------------------------------------------
    insertAccountsProjects.asp
    <!--#Include File="Connect.asp" -->

    <html>
    <body>
    <%
    Dim insertList
    insertList = Request.Form("check")

    insertList = "'" & Replace(insertList, ", ", "','") & "'"

    insertArray = split(insertList, ",")

    Project = Request.Form("pro") 'Get the Project id from the hidden
    field in choose user-file

    if insertList = "''" then

    'No items to insert
    Response.Write "You did not select any items to insert!" 'so far
    so good
    Response.Write Project 'just a check to see that project has the
    right value...it does !
    Else
    Dim SQLstring

    FOR i = 0 to ubound(insertArray)

    SQLstring = "INSERT INTO [AccountsProjects] ([Pnr],
    //25[ProjectID])" &_
    "VALUES (" & "'" & insertList(i) & "', '" & Project & "')"
    Con.Execute sqlString
    NEXT
    end if
    %>
    --------------------------------------------------------------------------
    Fredrik/Sweden Guest

  2. Similar Questions and Discussions

    1. insert multiple row
      How do i insert multiple rows in database. for example: I have 3 list: list1: a1,a2,a3,a4 list2: b1,b2,b3,b4 list3: c1,c2,c3,c4 I want to...
    2. insert multiple row and table
      I have table1 and table 2, one to many relationship. How do I save 3 rows in table 1 and one row in table 2 at the same time?
    3. Multiple DB Insert
      I have an XML file that has roughly 55,000 records. I need to parse the contents of the file and store it in a database. The problem I'm having is...
    4. Multiple Insert or Looping Insert
      I built an application on an Access DB that allows a dispatcher to log trucks in the field at their location as they call in. There are three...
    5. Insert Multiple INTO multiple table
      Is there an extension available that can insert into multiple database tables and then retrieve the ID of the first insert? Andy
  3. #2

    Default Re: multiple insert problem !

    Change insertList(i) to insertArray(i) in the for/next loop.

    Ray at home

    "Fredrik/Sweden" <fredda054@hotmail.com> wrote in message
    news:a501fefe.0310030321.5ec9b436@posting.google.c om...
    >
    > Error Type:
    > Microsoft VBScript runtime (0x800A000D)
    > Type mismatch
    > /VS_Files/insertAccountsProjects.asp, line 25
    > insertList = Request.Form("check")
    >
    > insertList = "'" & Replace(insertList, ", ", "','") & "'"
    >
    > insertArray = split(insertList, ",")
    >
    > FOR i = 0 to ubound(insertArray)
    >
    > SQLstring = "INSERT INTO [AccountsProjects] ([Pnr],
    > //25[ProjectID])" &_
    > "VALUES (" & "'" & insertList(i) & "', '" & Project & "')"
    > Con.Execute sqlString
    > NEXT
    > end if

    Ray at Guest

  4. #3

    Default Re: multiple insert problem !

    Off Course Ray !!! your absolutely right...it was just to obvious for me
    to see !!!
    Thank you again !!!
    (i think i'll have to say something about you in my project =)



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Fredrik Holm 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