Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple SQL Entries

Status
Not open for further replies.

Corneliu

Technical User
Sep 16, 2002
141
US
How can I make multiple entries in a SQL Database with just one form.
I sometimes get hardware where there is only 1 PO, but for like 100 items.
The information is the same, except for the serial number.
How can I enter the serial number in say a field of some kind and than Insert Into the database as separate records, but with the serial number different. This is what I have so far, which is for one record. What I do now is enter the serial number in the Notes Field and than have to search for quite some time to get each one or if the number of items is low, I enter them separately one by one.
Can you help me with this please, or let me know where I can get some information for this type issue?

SQL Statement:

<%

Set RS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
SqlString = &quot;SELECT PCs.PONumber, PCs.SerialNumber, PCs.Department, Department.Department, PCs.Requestor, Users.UserName, PCs.Notes, PCs.ReceivedBy, Technicians.TechName, PCs.Arrival, PCs.Brand, Manufacturer.Manufacturer, PCs.Model, PCs.Speed, PCs.RAM, PCs.HardDrive, PCs.Inventory, PCs.Temporary, PCs.Delivered, PCs.Location&quot;
SqlString = SqlString & &quot; FROM (((PCs INNER JOIN Department ON PCs.Department = Department.DepartmentID) INNER JOIN Users ON PCs.Requestor = Users.UserID) INNER JOIN Technicians ON PCs.ReceivedBy = Technicians.TechID) INNER JOIN Manufacturer ON PCs.Brand = Manufacturer.BrandID &quot;

Set RS = objConn.Execute ( SqlString )
%>

The Form:

<table width=&quot;100%&quot; border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;2&quot; bordercolor=&quot;#000000&quot; class=&quot;Graph&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;262&quot; height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Brand
of PC</div></td>
<td width=&quot;718&quot; rowspan=&quot;29&quot; valign=&quot;top&quot; bgcolor=&quot;EEEEE0&quot;><div align=&quot;center&quot;>Notes<BR>
<textarea name=&quot;Notes&quot; cols=&quot;55&quot; rows=&quot;28&quot; id=&quot;Select13&quot;></textarea>
</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;> <div align=&quot;right&quot;>
<select name=&quot;Brand&quot; size=&quot;1&quot; class=&quot;inputBox&quot; id=&quot;Select1&quot;>
<% WHILE NOT RS4.EOF %>
<option value=&quot;<%=RS4(&quot;BrandID&quot;)%>&quot;><%=RS4(&quot;Manufacturer&quot;)%></option>
<%
RS4.MoveNext
WEND
%>
</select>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Model</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input name=&quot;Model&quot; type=text class=&quot;inputBox&quot; id=&quot;Select2&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Speed (insert
only the number)</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input name=&quot;Speed&quot; type=text class=&quot;inputBox&quot; id=&quot;Select3&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>RAM (insert
only the number)</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input name=&quot;RAM&quot; type=text class=&quot;inputBox&quot; id=&quot;Select4&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Hard Drive
(insert only the number)</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input name=&quot;HardDrive&quot; type=text class=&quot;inputBox&quot; id=&quot;Select5&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>PO (If Known)</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input name=&quot;PONumber&quot; type=text class=&quot;inputBox&quot; id=&quot;Select6&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Serial Number</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input name=&quot;SerialNumber&quot; type=text class=&quot;inputBox&quot; id=&quot;Select7&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Department</div></td>
</tr>
<tr>
<td height=&quot;22&quot; nowrap bordercolor=&quot;#FFFFFF&quot;> <div align=&quot;right&quot;>
<select name=&quot;Department&quot; size=&quot;1&quot; class=&quot;inputBox&quot; id=&quot;select8&quot;>
<% WHILE NOT RS3.EOF %>
<option value=&quot;<%=RS3(&quot;DepartmentID&quot;)%>&quot;><%=RS3(&quot;Department&quot;)%></option>
<%
RS3.MoveNext
WEND
%>
</select>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Requestor</div></td>
</tr>
<tr>
<td height=&quot;22&quot; nowrap bordercolor=&quot;#FFFFFF&quot;> <div align=&quot;right&quot;>
<select name=&quot;Requestor&quot; size=&quot;1&quot; class=&quot;inputBox&quot; id=&quot;select9&quot;>
<% WHILE NOT RS2.EOF %>
<option value=&quot;<%=RS2(&quot;UserID&quot;)%>&quot;><%=RS2(&quot;UserName&quot;)%></option>
<%
RS2.MoveNext
WEND
%>
</select>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Received By</div></td>
</tr>
<tr>
<td height=&quot;22&quot; nowrap bordercolor=&quot;#FFFFFF&quot;> <div align=&quot;right&quot;>
<select name=&quot;ReceivedBy&quot; size=&quot;1&quot; class=&quot;inputBox&quot; id=&quot;select10&quot;>
<% WHILE NOT RS1.EOF %>
<option value=&quot;<%=RS1(&quot;TechID&quot;)%>&quot;><%=RS1(&quot;TechName&quot;)%></option>
<%
RS1.MoveNext
WEND
%>
</select>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Arrival Date</div></td>
</tr>
<tr>
<td height=&quot;19&quot; nowrap bordercolor=&quot;#FFFFFF&quot;> <div align=&quot;center&quot;>
<input name=&quot;Arrival&quot; type=text class=&quot;inputBox&quot; id=&quot;Select11&quot; value=&quot;<%= Date() %>&quot;>
</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;center&quot;>Inventory</div></td>
</tr>
<tr>
<td height=&quot;16&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input type=&quot;radio&quot; name=&quot;Inventory&quot; value=&quot;1&quot;>
Yes
<input name=&quot;Inventory&quot; type=&quot;radio&quot; value=&quot;2&quot; checked>
No</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;left&quot;>Temporary (YES
if the PC is given away Temp)</div></td>
</tr>
<tr>
<td height=&quot;16&quot; nowrap> <div align=&quot;center&quot;>
<input type=&quot;radio&quot; name=&quot;Temporary&quot; value=&quot;1&quot;>
Yes
<input name=&quot;Temporary&quot; type=&quot;radio&quot; value=&quot;2&quot; checked>
No</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;> <div align=&quot;left&quot;>Delivered? (If
the PC has been delievered)</div></td>
</tr>
<tr>
<td height=&quot;16&quot; nowrap bordercolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<input type=&quot;radio&quot; name=&quot;Delivered&quot; value=&quot;1&quot;>
Yes
<input name=&quot;Delivered&quot; type=&quot;radio&quot; value=&quot;2&quot; checked>
No</div></td>
</tr>
<tr>
<td height=&quot;14&quot; nowrap bgcolor=&quot;EEEEE0&quot;><div align=&quot;center&quot;>Location of
Equipment</div></td>
</tr>
<tr>
<td nowrap bordercolor=&quot;#FFFFFF&quot;> <div align=&quot;center&quot;>
<input name=&quot;Location&quot; type=text class=&quot;inputBox&quot; id=&quot;Select12&quot;>
</div></td>
<td bordercolor=&quot;#FFFFFF&quot;><div align=&quot;right&quot;>
<input name=&quot;Reset&quot; type=&quot;reset&quot; class=&quot;inputSubmit&quot; value=&quot;Reset&quot;>
<input name=&quot;Submit2&quot; type=&quot;submit&quot; class=&quot;inputSubmit&quot; value=&quot;Submit&quot;>
</div></td>
</tr>
</table>


The Insert Page:


<%

PONumber = TRIM( Request.Form( &quot;PONumber&quot;) )
SerialNumber = TRIM( Request.Form( &quot;SerialNumber&quot; ) )
Department = TRIM( Request.Form( &quot;Department&quot; ) )
Requestor = TRIM( Request.Form( &quot;Requestor&quot; ) )
Notes = TRIM( Request.Form( &quot;Notes&quot; ) )
ReceivedBy = TRIM( Request.Form( &quot;ReceivedBy&quot; ) )
Arrival = TRIM( Request.Form( &quot;Arrival&quot; ) )
Brand = TRIM( Request.Form( &quot;Brand&quot; ) )
Model = TRIM( Request.Form( &quot;Model&quot; ) )
Speed = TRIM( Request.Form( &quot;Speed&quot; ) )
RAM = TRIM( Request.Form( &quot;RAM&quot; ) )
HardDrive = TRIM( Request.Form( &quot;HardDrive&quot; ) )
Inventory = TRIM( Request.Form( &quot;Inventory&quot; ) )
Temporary = TRIM( Request.Form( &quot;Temporary&quot; ) )
Delivered = TRIM( Request.Form( &quot;Delivered&quot; ) )
Location = TRIM( Request.Form( &quot;Location&quot; ) )

sqlString = &quot;INSERT INTO PCs (PONumber,SerialNumber,Department,Requestor,Notes,ReceivedBy,Arrival,Brand,Model,Speed,RAM,HardDrive,Inventory,Temporary,Delivered,Location)&quot;
sqlString = sqlString & &quot; VALUES ('&quot; & PONumber & &quot;','&quot; & SerialNumber & &quot;','&quot; & Department & &quot;','&quot; & Requestor & &quot;','&quot; & Notes & &quot;','&quot; & ReceivedBy & &quot;','&quot; & Arrival & &quot;','&quot; & Brand & &quot;','&quot; & Model & &quot;','&quot; & Speed & &quot;','&quot; & RAM & &quot;','&quot; & HardDrive & &quot;','&quot; & Inventory & &quot;','&quot; & Temporary & &quot;','&quot; & Delivered & &quot;','&quot; & Location & &quot;')&quot;
SET RS = objConn.Execute( sqlString )


%>

Is there a way to do multiple entries with one form from what I have?

THANK YOU...
 
It sounds like you would benefit from having the code for your form and your form handler on the same asp page. When you detect that the page has been called from itself (the form has posted) you insert the data and redisplay the form with all fields populated. Allow the user to make changes and then submit the form again. You will have to develop a method to prevent the user from adding the exact same data twice. It would also probably be helpful to show the user what data already exists in the db.....


form.asp

<%
Set objConn = Server.CreateObject( &quot;ADODB.Connection&quot; )
Set objCmd = Server.CreateObject( &quot;ADODB.Command&quot; )
Set objRS = Server.CreateObject( &quot;ADODB.Recordset&quot; )
objConn.Open Application(&quot;connectString&quot;)
Set objCmd.ActiveConnection = objConn
objCmd.CommandTimeout = 60

If Request.ServerVariables( &quot;REQUEST_METHOD&quot; ) = &quot;POST&quot; Then
strSQL = &quot;Insert into myTable (field1, field2) VALUES &quot; & request(&quot;field1&quot;) & &quot;,'&quot; & request(&quot;field2&quot;) & &quot;'&quot;
objConn.execute(strSQL)
end if

field1Val = request(&quot;field1&quot;)
if field1Val = &quot;&quot; then field1Val = null

with objCmd
.commandText = &quot;usp_newProjectForm&quot;
.CommandType =adCmdStoredProc
.parameters(1) = field1Val
end with
set objRS = objCmd.execute()

htmlSTR = &quot;<h3>This data is already in the database</h3><table border=1>&quot;
do while not objRS.EOF
htmlSTR = htmlSTR & &quot;<tr><td>&quot; & objrs(&quot;field1&quot;) & &quot;</td><td>&quot; & objrs(&quot;field2&quot;) & &quot;</td></tr>&quot;)
objrs.movenext
loop

%>

<%=htmlStr%>

<form>

<% if request(&quot;field1&quot;) = &quot;&quot; then %>
<input name=field1>
<% else %>
<input type=hidden name=field1 value=&quot;<%=request(&quot;field1&quot;)%>&quot;><%=request(&quot;field1&quot;)%>
<% end if %>

<input name=field2>

<input type=submit value=&quot;Add to current record&quot;>
<input type=button value=&quot;Start New Record&quot; onClick=&quot;javascript: document.location='form.asp'&quot;> -----------------------------------------------------------------
[pc] Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top