Multiple Table Add/Insert in SQL Server:
Code:
add.asp:
Highlight
<%@ Language=VBScript %> <%option explicit%> <%if (request.querystring ("Submitted")) = "True" then%>
The Record has been Submitted
<%else%> <% dim conn dim rs dim sSQL Set conn = ConnectSQLNT("DataBaseName", "ServerName") %>
FieldName1:
FieldName2:
FieldName3:
<% conn.Close: set conn=nothing %> <%end if%>
dbinsert.asp:
Highlight
<%@ Language=VBScript %> <%option explicit%> <% Dim cmd Dim conn Dim strTemp Set conn = ConnectSQLNT("DataBaseName", "ServerName") Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = conn cmd.CommandType = adCmdStoredProc cmd.CommandText = "sp_InsertTableName" cmd.Parameters.Append(cmd.CreateParameter("@FieldName1", adInteger, adParamInput, , Request.form("cboFieldName1"))) cmd.Parameters.Append(cmd.CreateParameter("@FieldName2", adBoolean, adParamInput, , Request.form("cboFieldName2"))) cmd.Parameters.Append(cmd.CreateParameter("@FieldName3", adVarChar, adParamInput, 255, Request.form("cboFieldName3"))) cmd.execute Set cmd=nothing set Conn=nothing response.redirect "add.asp?Submitted=True" %>
sp_InsertTableName:
Highlight
CREATE PROCEDURE dbo.sp_InsertTableName @FieldName1 int, @FieldName2 bit, @FieldName3 varchar(255) AS DECLARE @PrimaryKeyField int INSERT INTO Table1 (FieldName1, FieldName2) VALUES (@FieldName1, @FieldName2) SET @PrimaryKeyField = @@IDENTITY INSERT INTO Table2 (FieldName3) VALUES (@FieldName3)