473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

ASP Insert Many-To-One: How-To?

blyxx86
256 100+
Hello all,
I'm somewhat familiar with ASP, SQL and VBScript... Sooo.. I can get it done, but somehow I think there is a better way than I am thinking.

I am trying to create a page for people to add multiple line items to a request. I have two tables set up in a many-to-one relationship. tblRequest and tblRequestDetail
Expand|Select|Wrap|Line Numbers
  1. tblRequest
  2. RequestID; Autonumber; Indexed No Dupes
  3. CustomerID; PK
  4. CustomerTicket; PK (multiple customers can have the same ticket number, but no one customer can have the same ticket number, so this is how the PK is related)
  5. Etc;
  6.  
  7. tblRequestDetail
  8. RequestDetailID; PK; AutoNumber
  9. RequestID; FK
  10. ProductID;
  11. ModelID;
  12. etc;
  13.  
I am a little weary on how to set up the "Request Form"... Especially when it comes to handling the insert of the data in the tblRequestDetail table.

Do I have to call a SELECT tblRequest.RequestID FROM tblRequest WHERE ((tblRequest.CustomerTicket = X) AND (tblRequest.CustomerID = Y)) to insert the value into tblRequestDetail.RequestID??

Maybe I can just do an INSERT INTO.... WHERE ((tblRequest.CustomerTicket = X) AND (tblRequest.CustomerID = Y)) after I call the .Update from the first insert of the tblRequest table??

I don't want to really go headlong into this (it's my first attempt at creating an insert form) and be going the wrong direction.

THANK YOU!!!!
Nov 30 '07 #1
5 1204
blyxx86
256 100+
I have created the following testform...

Expand|Select|Wrap|Line Numbers
  1. <% If Request.Form("CustomerID")<>"" And Request.Form("CustomerTicket")<>"" Then %>
  2. <% Dim rs, sql, reqID %>
  3. <% Set rs = server.createObject("adodb.recordset") %>
  4. <% sql = "SELECT * FROM tblRequest" %>
  5. <% rs.open sql, Conn,2,3 %>
  6.  
  7.     <%=Request.Form("CustomerID") %> <br />
  8.     <%=Request.Form("CustomerTicket") %> <br />
  9.     <%=Session("Logon") %> <br />
  10.     <%
  11.       rs.addNew
  12.       rs("EnteredByNet") = Session("Logon")
  13.       rs("CustomerID") = CInt(Request.Form("CustomerID"))
  14.       rs("CustomerTracking") = Request.Form("CustomerTicket")
  15.       rs("RequestTypeID") = 1
  16.       rs.update
  17.       rs.close
  18.  
  19.       sql = "SELECT tblRequest.RequestID FROM tblRequest WHERE tblRequest.CustomerID = 1 AND tblRequest.CustomerTracking=""" & Request.Form("CustomerTicket") & """"
  20.       rs.open sql, Conn, 2, 3
  21.       reqID = rs("RequestID")
  22.       rs.close
  23.  
  24.       sql = "SELECT * FROM tblRequestDetail"
  25.       rs.open sql, Conn, 2, 3
  26.       rs.addNew
  27.       rs("RequestID") = reqID
  28.       rs("ProductID") = 39
  29.       rs("EnteredByNet") = Session("Logon")
  30.       rs.update
  31.       %>
  32.  
  33. <% Else %>
  34. <form action="request.asp" method="post">
  35.     <input name="CustomerID" type="text" />
  36.     <input name="CustomerTicket" type="text" />
  37.     <input name="" type="submit" />
  38. </form>
  39. <% End If %>
  40.  
It's not very clean, and not very efficient (proof of concept design)...

What I really need to do is generate something that first asks for the information in the tblRequest table, and once that is input have a new section display, that shows tblRequestDetail table information. To display something like....
Expand|Select|Wrap|Line Numbers
  1. <table width="85%" border="1">
  2.   <tr>
  3.     <td>tblRequest.CustomerID</td>
  4.     <td>tblRequest.CustomerTicket</td>
  5.     <td>tblRequest.LocationCode</td>
  6.     <td>tblRequest.EnteredBy</td>
  7.     <td>tblRequest.ReqType</td>
  8.   </tr>
  9.   <tr>
  10.     <td>&nbsp;</td>
  11.     <td>tblRequestDetail.ProductID</td>
  12.     <td>tblRequestDetail.Qty</td>
  13.     <td>tblRequestDetail.Serial</td>
  14.     <td>tblRequestDetail.Type</td>
  15.   </tr>
  16.   <tr>
  17.     <td>&nbsp;</td>
  18.     <td>tblRequestDetail.ProductID</td>
  19.     <td>tblRequestDetail.Qty</td>
  20.     <td>tblRequestDetail.Serial</td>
  21.     <td>tblRequestDetail.Type</td>
  22.   </tr>
  23.   <tr>
  24.   <form action="request.asp" method="post">
  25.     <td><input type="submit" value="Add New" /></td>
  26.     <td><input name="tblRequestDetail.ProductID" type="text" /></td>
  27.     <td><input name="tblRequestDetail.Qty" type="text" /></td>
  28.     <td><input name="tblRequestDetail.Serial" type="text" /></td>
  29.     <td><input name="tblRequestDetail.Type" type="text" /></td>
  30.   </form>
  31.   </tr>
  32. </table>
  33.  
See the last row in the table would have the ability to add more items to the request. I am merely looking for guidance on where to go with the selection structure to accomplish a pseudo-shopping cart? Any help is greatly appreciated.
Nov 30 '07 #2
omerbutt
638 512MB
you havent mentioned the names of the files which code is in which file atleast mention it so that we could further see that code
Regards,
Omer
Dec 1 '07 #3
blyxx86
256 100+
Thanks for the reply. :) (Even though it didn't show up when I hit "Reply" it showed me your quoted text.)

I'll give you as much information as possible.
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <% 
  3. If Session("Logon") = "" Then
  4. Session("LastPage") = Request.ServerVariables("URL")
  5. Response.Redirect("login.asp")
  6. End if
  7. %>
  8. <!--#include file="connstr.asp"-->
  9. <!--#include file="includes\common.asp"-->
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml">
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  14. <title>Request New</title>
  15. </head>
  16.  
  17. <body>
  18. <% If Request.Form("CustomerID")<>"" And Request.Form("CustomerTicket")<>"" Then %>
  19. <% Dim rs, sql, reqID %>
  20. <% Set rs = server.createObject("adodb.recordset") %>
  21. <% sql = "SELECT * FROM tblRequest" %>
  22. <% rs.open sql, Conn,2,3 %>
  23.  
  24.     <%=Request.Form("CustomerID") %> <br />
  25.     <%=Request.Form("CustomerTicket") %> <br />
  26.     <%=Session("Logon") %> <br />
  27.     <%
  28.       rs.addNew
  29.       rs("EnteredByNet") = Session("Logon")
  30.       rs("CustomerID") = CInt(Request.Form("CustomerID"))
  31.       rs("CustomerTracking") = Request.Form("CustomerTicket")
  32.       rs("RequestTypeID") = 1
  33.       rs.update
  34.       rs.close
  35.  
  36.       sql = "SELECT tblRequest.RequestID FROM tblRequest WHERE tblRequest.CustomerID = 1 AND tblRequest.CustomerTracking=""" & Request.Form("CustomerTicket") & """"
  37.       rs.open sql, Conn, 2, 3
  38.       reqID = rs("RequestID")
  39.       rs.close
  40.  
  41.       sql = "SELECT * FROM tblRequestDetail"
  42.       rs.open sql, Conn, 2, 3
  43.       rs.addNew
  44.       rs("RequestID") = reqID
  45.       rs("ProductID") = 39
  46.       rs("EnteredByNet") = Session("Logon")
  47.       rs.update
  48.       rs.close
  49.       %>
  50. <% Else %>
  51. <form action="request.asp" method="post">
  52.     <input name="CustomerID" type="text" />
  53.     <input name="CustomerTicket" type="text" />
  54.     <input name="" type="submit" />
  55. </form>
  56. <% End If %>
  57. <table width="85%" border="1">
  58.   <tr>
  59.     <td>tblRequest.CustomerID</td>
  60.     <td>tblRequest.CustomerTicket</td>
  61.     <td>tblRequest.LocationCode</td>
  62.     <td>tblRequest.EnteredBy</td>
  63.     <td>tblRequest.ReqType</td>
  64.   </tr>
  65.   <tr>
  66.     <td>&nbsp;</td>
  67.     <td>tblRequestDetail.ProductID</td>
  68.     <td>tblRequestDetail.Qty</td>
  69.     <td>tblRequestDetail.Serial</td>
  70.     <td>tblRequestDetail.Type</td>
  71.   </tr>
  72.   <tr>
  73.     <td>&nbsp;</td>
  74.     <td>tblRequestDetail.ProductID</td>
  75.     <td>tblRequestDetail.Qty</td>
  76.     <td>tblRequestDetail.Serial</td>
  77.     <td>tblRequestDetail.Type</td>
  78.   </tr>
  79.   <tr>
  80. <!-- This is the part that I need to be able to add multiple lines to the Request -->
  81. <!-- Maybe I'm hoping it will be short and easy, but there really is a lengthy loop involved, is there not? -->
  82.   <form action="request.asp" method="post">
  83.     <td><input type="submit" value="Add New" /></td>
  84.     <td><input name="tblRequestDetail.ProductID" type="text" /></td>
  85.     <td><input name="tblRequestDetail.Qty" type="text" /></td>
  86.     <td><input name="tblRequestDetail.Serial" type="text" /></td>
  87.     <td><input name="tblRequestDetail.Type" type="text" /></td>
  88.   </form>
  89.   </tr>
  90. </table>
  91.  
  92. </body>
  93. </html>
  94.  
Dec 3 '07 #4
omerbutt
638 512MB
Hello all,
Maybe I can just do an INSERT INTO.... WHERE ((tblRequest.CustomerTicket = X) AND (tblRequest.CustomerID = Y)) after I call the .Update from the first insert of the tblRequest table??

I don't want to really go headlong into this (it's my first attempt at creating an insert form) and be going the wrong direction.

THANK YOU!!!!
you cannot use WHERE clause in the insert statement in the SQL query
Dec 4 '07 #5
blyxx86
256 100+
I realized that not too long after I wrote it when I tried. The HTML I provided showed a different approach that is working now, but I still need help creating the form. I thought it would be easy, but it's not being too easy.

So far what I have works... Using a SELECT of the PK(s) in the related table. However, I am thinking I may want to try for an array set-up, before sending the update to the table (can do error checking and everything in the array first).

I am stumped at how to create a form that will allow me to continuously add new items to it, though. Any guidance there? It would be similar to a shopping cart, except users select from a drop down menu what they want to add. Update the quantity and add any additional notes.
Dec 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ford Desperado | last post by:
I've been reading the docs and playing around, but I'm still not getting the difference. For instance, create table a(i int check(i>0)) create table a_src(i int) go create unique index ai on...
2
by: Daniel Tan | last post by:
I got a syntax error in SQL insert into statement , hope someone can help me .Thanks. job_search = "='" & Me.Jobno & "' " sqlstr = "INSERT INTO Custorder (job_order) " & _ "values " &...
7
by: Bruce A. Julseth | last post by:
A couple of questions about a Generated Insert Procedure. 1. Why is there a "SELECT " statement after the insert? 2. This SELECT statement has "WHERE (PrimaryKey = @@IDENTITY)". I "assume"...
8
by: shenanwei | last post by:
I have 2 same windows machine, same instance configure and Database , all run DB2 UDB V8.1.5 Test 1 : create table OUT_1 (LINE VARCHAR(350), LINENUMBER INTEGER NOT NULL GENERATED ALWAYS AS...
7
by: fintudet | last post by:
Hello. During some experimentation with DB2 decimal numbers representations, I have discovered very unexpected behaviour of the global temporary table. Consider this example. Such I had...
3
by: mosscliffe | last post by:
I created a new table in Visual Web Developer for SQL Server Express 2005. I created a 'gridview' by dragging the table onto an empty web form in Visual Developer Express. Clicked on the smart...
0
by: macupryk | last post by:
{System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ProjectResponse__ProjectQuestionId". The conflict occurred in database "RG_ProjectData", table...
7
by: Mark Knochen | last post by:
Hello, i have a php-script with a mysql_query ... $insert = mysql_query("INSERT INTO $table (textID,redaktion) VALUES ('$_POST','$row_startseiten')"); I get no mysql_error, if i copy the...
3
by: Ultrak The DBA | last post by:
As a converted sybase dba, I have a question. In sybase a command can be executed multiple times by placing a go 1000 at the end of the statement. Such as: insert into a (col1, col2)...
11
by: mdboldin | last post by:
I hav read on this forum that SQL coding (A) below is preferred over (B), but I find (B) is much faster (20-40% faster) (A) sqla= 'INSERT INTO DTABLE1 VALUES (%d, %d, %d, %f)' % values...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.