|
Hi,
i need some help with my asp page,firstly,i have dynamic list on in my form i.e the list values are dirrectly from the sql server, what i want to do is,once the from is submiited i need to request the selected value by the user and insert it in to the database how can i do this. the name i have given to the dynamic field in the form is Machine, and it needs to go under a field in the database table called machine_ID so how would i request or achieve to get this data from my form and insert in to the database.
|
|
|
I used a stored procedure to insert into the database.
First this code is on my "confirmation" page or the page you take them to after they click the submit button.
'request the values from the form page
<%
selPmtX = request("chkPForm1")
selBillX =request("chkBill")
selAccptX = request("chkPAcc1")
selTypeX = request("chkTypes")
TempName = request("TempName")
TempDesc = request("TempDesc")
Response.Write TempDesc
if TempName <> "" then
'do an insert into the database
set Rptcn = CreateObject("ADODB.Connection")
set Rptrs = CreateObject("ADODB.Recordset")
Rptcn.ConnectionString="Provider=SQLOLEDB.1;Password=;User ID=sa;Initial Catalog=DynReporting;Data Source=GAALP2BLTOPAD15"
Rptcn.CursorLocation = 3
Rptcn.Open
'use the stored procedure
sqlIn = "Execute sp_InsertTemplate '" & _
XName & "','" & _
TempName & "','" & _
TempDesc & "','" & _
selTypeX & "','" & _
selTeamX & "','" & _
selBillX & "','" & _
selPmtX & "','" & _
selAccptX & "'"
Err.clear
If Err.number <> 0 then
TrapError Err.Description
End If
set Rptrs = Rptcn.Execute(sqlIn)
====================================
Then the SQL stored procedure looks like this:
CREATE PROCEDURE sp_InsertTemplate
(@XName varchar(10),
@TemplateName varchar(50),
@TempDesc varchar(500),
@ReqType varchar(500),
@Team varchar(500),
@Billing varchar(500),
@Payment varchar(500),
@Accept varchar(500))
AS
insert into DynamicReports (UserID, TemplateName, TempDesc, ReqType, Team, Billing, Payment, Accept, CreateDate)
values (@XName, @TemplateName, @TempDesc, @ReqType, @Team, @Billing, @Payment, @Accept, GetDate())
GO
==========================
it's really no different than if the inserting non-dynamically generated form elements. You would insert Machine where I have chkTeam1 in the line:
selTeamX = request("chkTeam1")
(Name the variable it read into anything you want.)
In the stored procedure is when I refer to the appropriate column, where I have Payment you would put machine_id. That stored procedure is tricky, don't have a hair out of place or it won't work. Make sure you put the variables and the column names in the right order and make sure you have all your commas in the right place. Good luck, hope this helps.
|
|
|
|
|
|
|
|