Ask a Question related to ASP Database, Design and Development.
-
Fredrik/Sweden #1
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
-
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... -
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? -
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... -
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... -
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 -
Ray at #2
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
-
Fredrik Holm #3
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



Reply With Quote

