Forums
This topic is locked
Repeat Region Form to Insert Record
Posted 23 Dec 2002 18:06:00
1
has voted
23 Dec 2002 18:06:00 Jeff DeHaven posted:
Greetings All,I have a rather daunting problem that I cannot seem to figure out. I have a table [dbo.SupplyRequest] that will accomodate supply requests (SQL Server) This table has an ID, a Supply ID and a Quantity. There is another table [dbo.SupplyReference] that is the reference for this- it contains a SupplyID (referenced to supplyID) and a text description.
The .asp web page that I created displays a quantity text field next to each text description and a hidden field with the supplyID, and uses a repeat region to display all of the different supplies. What you end up with is a list of all the supplies with a textfield before it prompting for the quantity of the supply, this works fine.
Unfortunately I have yet to find a way to update the table properly, since it can only accomodate one update at a time instead of the whole list- so I guess I need some kind of code snippet that goes through the form and puts in each value one after another until it is done down the list--
Has anyone created a server behavior for taking a dynamic listing of objects and updating a single database table multiple times from it? Or is there a better way for me to go about this?
Thank you in advance for any help provided!
Edited by - jdehaven on 23 Dec 2002 18:07:09
Replies
Replied 23 Dec 2002 19:25:26
23 Dec 2002 19:25:26 Owen Eastwick replied:
Well, you're half way there, you allready have a repeat region within a form.
So, set up a stored procedure, something like:
----------------------------------------------------
CREATE PROCEDURE spInsertSupplyQuantities
@SupplyID int,
@Quantity int
AS
SET NOCOUNT ON
UPDATE SupplyRequest SET Quantity = @Quantity WHERE SupplyID = @SupplyID
SET NOCOUNT OFF
Go
------------------------------------------------------
Make the form submit back to the same page, now use <b>command (Stored Procedure)</b> to call the stored procedure from the page, then move it within the repeat region and place a condition around it so it only executes once the form is submitted, something like:
------------------------------------------------------------------------------------------
<form name="form1" method="post" action="ThisPage.asp">
<table width="400" border="0" cellspacing="0" cellpadding="5">
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td width="138"><%=(Recordset1.Fields.Item("Whatever".Value)%></td>
<td width="242">
<input type="text" name="txtQuantity<%= <b>Repeat1__numRows</b> %>"> <input type="hidden" name="hidSupplyID<%= <b>Repeat1__numRows</b> %>"></td>
</tr>
<% If Request("Submit" <> "" Then '<b>The UPDATE command is only executed once the form is submited </b> %>
<%
Dim Command1__SupplyID
Command1__SupplyID = ""
if(Request("SupplyID" & <b>Repeat1__numRows</b> <> "" then Command1__SupplyID = Request("SupplyID" & <b>Repeat1__numRows</b>
Dim Command1__Quantity
Command1__Quantity = "0"
if(Request("Quantity" & <b>Repeat1__numRows</b> <> "" then Command1__Quantity = Request("Quantity" & <b>Repeat1__numRows</b>
%>
<%
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_YourConnection_STRING
Command1.CommandText = "dbo.spInsertSupplyQuantities"
Command1.CommandType = 4
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Parameters.Append Command1.CreateParameter("@RETURN_VALUE", 3, 4)
Command1.Parameters.Append Command1.CreateParameter("@SupplyID", 3, 1,4,Command1__SupplyID)
Command1.Parameters.Append Command1.CreateParameter("@Quantity", 3, 1,4,Command1__Quantity)
Command1.Execute()
%>
<% End If %>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Update"></td>
</tr>
</table>
</form>
------------------------------------------------------------------------------------------
Notice how I've re-used the <b>Repeat1__numRows</b> variable throughout to provide a unique number for the hidden field and textfield each time through the loop.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Edited by - oeastwick on 23 Dec 2002 19:32:56
So, set up a stored procedure, something like:
----------------------------------------------------
CREATE PROCEDURE spInsertSupplyQuantities
@SupplyID int,
@Quantity int
AS
SET NOCOUNT ON
UPDATE SupplyRequest SET Quantity = @Quantity WHERE SupplyID = @SupplyID
SET NOCOUNT OFF
Go
------------------------------------------------------
Make the form submit back to the same page, now use <b>command (Stored Procedure)</b> to call the stored procedure from the page, then move it within the repeat region and place a condition around it so it only executes once the form is submitted, something like:
------------------------------------------------------------------------------------------
<form name="form1" method="post" action="ThisPage.asp">
<table width="400" border="0" cellspacing="0" cellpadding="5">
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td width="138"><%=(Recordset1.Fields.Item("Whatever".Value)%></td>
<td width="242">
<input type="text" name="txtQuantity<%= <b>Repeat1__numRows</b> %>"> <input type="hidden" name="hidSupplyID<%= <b>Repeat1__numRows</b> %>"></td>
</tr>
<% If Request("Submit" <> "" Then '<b>The UPDATE command is only executed once the form is submited </b> %>
<%
Dim Command1__SupplyID
Command1__SupplyID = ""
if(Request("SupplyID" & <b>Repeat1__numRows</b> <> "" then Command1__SupplyID = Request("SupplyID" & <b>Repeat1__numRows</b>
Dim Command1__Quantity
Command1__Quantity = "0"
if(Request("Quantity" & <b>Repeat1__numRows</b> <> "" then Command1__Quantity = Request("Quantity" & <b>Repeat1__numRows</b>
%>
<%
set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_YourConnection_STRING
Command1.CommandText = "dbo.spInsertSupplyQuantities"
Command1.CommandType = 4
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Parameters.Append Command1.CreateParameter("@RETURN_VALUE", 3, 4)
Command1.Parameters.Append Command1.CreateParameter("@SupplyID", 3, 1,4,Command1__SupplyID)
Command1.Parameters.Append Command1.CreateParameter("@Quantity", 3, 1,4,Command1__Quantity)
Command1.Execute()
%>
<% End If %>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Update"></td>
</tr>
</table>
</form>
------------------------------------------------------------------------------------------
Notice how I've re-used the <b>Repeat1__numRows</b> variable throughout to provide a unique number for the hidden field and textfield each time through the loop.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Edited by - oeastwick on 23 Dec 2002 19:32:56
Replied 24 Dec 2002 21:59:15
24 Dec 2002 21:59:15 Jeff DeHaven replied:
You are the man!! Thank you for your assistance!!