Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2003, 04:08 PM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default Add multiple records with one form submission

Hi Everyone:

I have a form which has a field for the date and then 8-10 dropdown menus where the user can select a number of hours for the chosen date. Each dropdown menu is a combination of three dropdown menus which is only a field in the db. For example, instead entering a number (8.00) in a textfield, I let the user select number 8 from the first dropdown menu, 0 from the second dropdown menu, another 0 from the third dropdown menu. After that, I need to combine all three numbers into 8.00.

What I want to do is add a new record for each time that has a value. For example, the user completes the date field and then select 8.00 in mnuHour1, 4.50 in mnuHour2 and 5.00 in mnuHour3as the above steps. mnuHour4 through mnuHour8 are not selected. Upon submit, I want to add a 3 new records to the db. The db has two fields, Day and NumberofHour. So the entry for Day will be either the same or different for all three new records and NumberofHour will be different. Any ideas on what my SQL would look like or if this is even possible?

Thanks,

Quinn
 
Old December 12th, 2003, 04:26 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You'll need to create a single INSERT statement for each row you plan on inserting. In ASP you'll need to construct the final values to insert. Then you can call the insert as many times as you want. To minimize the calls to SQL, you could make a single call with all the statements together:

INSERT INTO table(dayfield, hourfield) VALUES('<days>','<hours>');INSERT INTO table(dayfield, hourfield) VALUES('<days>','<hours>');INSERT INTO table(dayfield, hourfield) VALUES('<days>','<hours>');...

When you make the call to execute the statent in SQL, all the statements will execute. You just need to separate them with ;

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 12th, 2003, 05:21 PM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default

Peter:

Thanks for your quick reply. My point is can I use the For... Next to loop through the Insert statement. The following code is working fine if I use a textfield for the hour entry.

<%
Dim iCount
iCount = 0

For i = 1 to 5
    If Request("txtDate" & i) > " " Then
        iCount = iCount + 1
    End If
Next
%>

<%
    strEmpID = Request("mnuName")
    strTrans = Request("txtTransType")
For i=1 to iCount
    strHour = Request("txtHour" & i)
    strHour = Request("mnuNum" & i)
    strDate = Request("txtDate" & i)
    strType = Request("mnuType" & i)

iSQL = "INSERT INTO tTimeOffDetails (empID, dateTransaction, timeOffHour,"
iSQL =iSQL & " timeOffType, transactionType)"
iSQL = iSQL & " VALUES('"& strEmpID &"', '"& strDate &"' , '"& strHour &"',"
iSQL = iSQL & " '"& strType &"', '"& strTrans &"');"

Set rsInsert = objConnection.execute(iSQL)

Next
%>

If I use dropdown menu for the hour entry, I change my code to this, but it is not working.
<%
strHour = Cstr(Request("mnuNum" & i))+"."+Cstr(Request("mnuNum" & i))+CStr(Request("mnuNum" & i))

%>

Thanks,

Quinn
 
Old December 13th, 2003, 09:27 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It would appear that this won't work because you are requesting the same form field for each part of the hour entry. Shouldn't you have a mnuNumA+i, mnuNumB+i, mnuNumC+i to break apart the parts of the hour?

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add multiple labels to a form at run time peter-h Visual Basic 2005 Basics 5 September 22nd, 2007 04:29 AM
Insert multiple records from form lorirobn Access 2 April 9th, 2007 03:08 PM
How to Add/Delete/Update multiple records in DB? mmwaikar ADO.NET 1 September 20th, 2003 11:41 AM
Update or add multiple table records rosenzl VB.NET 3 June 12th, 2003 01:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.