ASP kod: Typ något sånt här:Hur returnera en OUTPUT PARAMETER från sql procedur till VB
TestName = "Olle Orm"
strSQL = "insNewTest '" & TestName & "'"
Set objRs = Server.CreateObject("DBStugor.DB")
ReturnId = objRs.executeSQL(strSQL)
SQL Procedur:
ALTER PROC insNewTest
@TestName varchar(50),
@ReturnId int OUTPUT
AS
INSERT INTO tblTest
(TestName)
VALUES
(@TestName)
SELECT @ReturnId = @@IDENTITY
VB komponent:
Public Function executeSQL(ByVal strSQL As String)
Dim DBConn As ADODB.Connection
'Skapa en anslutning
Set DBConn = addConnection()
'kör frågan
DBConn.Execute strSQL
DBConn.Close
Set DBConn = Nothing
End Function
Vill få ut @ReturnId från sqlproceduren till vbkomponenten så att jag kan returnera den till asp sidan.Sv: Hur returnera en OUTPUT PARAMETER från sql procedur till VB
Public Function InsertNewTest(Value As Variant) As Variant
Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Set con = addConnection()
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = con
cmd.CommandText = "insNewTest"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("TestName", adVarChar, adParamInput, 50, "")
cmd.Parameters.Append cmd.CreateParameter("ReturnId", adInteger, adParamOutput)
cmd.Execute , , adExecuteNoRecords
InsertNewTest = cmd.Parameters("ReturnId")
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
con.Close
Set con = Nothing
End Function