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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert data from table?

Status
Not open for further replies.

choohean

Technical User
Jan 15, 2002
57
MY
I got one table that have many rows with same attribute! How do I write a function to insert my data into database? Any one can please give me a hand...
 
Is it a table on the web page? Can you show a couple of rows here?
 
Erm.... Ok, in my web site got a table with few rows of textbox that will get input..is such and array things...
 
Try this. Here is a Sub to send data from all columns. If you have several rows you will need to add another loop for them, or call the sub for each row. Your table's fields shoud be called so you can loop through them (in my case they are called parameter1, parameter2, ....., parametern).

Const adVarChar = 200
Sub SendData()
Set cmdQuery = Server.CreateObject("ADODB.Command")
With cmdQuery
.ActiveConnection = dcnDB
.CommandType = adCmdStoredProc
.CommandText = "sp_SendData"
'parameters for all n columns
For N=1 to n
Dim strParameter
strParameter=Request.Form("parameter" & N)
.Parameters.Append = .CreateParameter("@parameter" & N, adVarChar, adParamInput, 50, strParameter)
Next
.Execute
End With
Set cmdQuery = Nothing
End Sub

Here is how your SQL stored procedure will look like:
CREATE PROCEDURE [user].[sp_SendData]
@parameter1 VARCHAR(50),
@parameter2 VARCHAR(50),
.
.
@parametern VARCHAR(50)
AS
INSERT INTO table
VALUES (@parameter1, @parameter2, ...., @parametern)

This is the simplest form of what you will need to do, your insert will probably be more complicated, but basically, the easiest way is to send all values from the page to the stored procedure, and then do whatever you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top