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...
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.