Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 12th, 2003, 04:08 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old December 12th, 2003, 04:26 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
Reply With Quote
  #3 (permalink)  
Old December 12th, 2003, 05:21 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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
Reply With Quote
  #4 (permalink)  
Old December 13th, 2003, 09:27 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:15 PM.


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