Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21993

Must declare the scalar variable

$
0
0
Hi folks. Total newbie here. Trying to use VB6 with SQL 2008 to execute a stored procedute. Net end result it to pass procedure 1 input parm (a tablename) and have the procedure return me 1 output parm (the recordcount for that passed tablename). Seem simple enough, but I can only get 1/2 to work, not both parts together. I frequently need recordcount and performance-wise in VB6/ADO this is blazing. No matter what I do I get error that "must declare the scalar variable "Param1"

HELP! ITS DRIVING ME NUTS!!!

--------------------------------------------------------------------------
Stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetRecordCount]
@tablename As nvarchar(50), @Param1 As nvarchar(50) Output
As
Declare @srctable as nVarchar
Set @srctable = @tablename

EXEC ('Select @Param1 = Count(*) FROM ' + @srctable)
---------------------------------------------------------------------------

VB6 Code to call it:
Dim count As Variant

Dim CMD As ADODB.Command
Dim prm1 As New ADODB.Parameter
Dim prm2 As New ADODB.Parameter

Set CMD = New ADODB.Command
CMD.ActiveConnection = gDB
CMD.CommandType = adCmdStoredProc
CMD.CommandText = "GetRecordCount"

Set prm1 = CMD.CreateParameter("@tablename", adChar, adParamInput, 100)
Set prm2 = CMD.CreateParameter("@Param1", adBigInt, adParamOutput, 20)

prm1.value = "SAMPLES" '<----- passing it the name of table that I need to be var in SELECT string below

CMD.Parameters.Append prm1
CMD.Parameters.Append prm2

CMD.Execute Options:=adExecuteNoRecords

count = CMD("param1") '<------- just want to return the OUTPUT VAR to here as "recordcount"

Set prm1 = Nothing
Set CMD = Nothing

Viewing all articles
Browse latest Browse all 21993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>