codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Get dynamic data from form and add to database Help  arfan786 at 12:07 on Thursday, October 23, 2003
 

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.

  Re: Get dynamic data from form and add to database Help  mikoniko at 15:33 on Wednesday, November 19, 2003
 

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.









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005