Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning Values when using Store Procedures
Message
From
30/06/2006 04:03:45
 
 
To
29/06/2006 04:53:14
General information
Forum:
Visual Basic
Category:
SQL Server
Miscellaneous
Thread ID:
01132618
Message ID:
01132996
Views:
11
Thanks for pointing me to the right direction! But I'm still only half-way to my predicament. It works in Query Analyzer, but I can't get it right in VB yet


Stored Procedure in SQL Server
CREATE PROCEDURE AddRecord @myNewKey INT OUTPUT
AS

INSERT INTO testTable1(myText) VALUES('tests')

SELECT @myNewKey  = @@IDENTITY
GO
Output when called in Query Analyzer is correct, using the T-SQL statements (a one-field, one row output)
DECLARE @i INT
EXECUTE AddRecord @i OUTPUT
SELECT @i As MyKey
- - - - - - output - - - - - -
MyKey
30
VB6 code
   Dim mySQL As String
   Dim rsFetch As ADODB.Recordset
   mySQL = "DECLARE @i INT" & vbCrLf _
         & "EXECUTE AddRecord @i OUTPUT" & vbCrLf _
         & "SELECT @i As MyKey"
   
   Set rsFetch = New ADODB.Recordset  
   
   With rsFetch
      .Open mySQL, dbMain
      Text1.Text = !MyKey
      .Close
    End With
The above VB code gnerates the error
"Item cannot be found in the collection corresponding to the requested name or ordinal."
on the line
Text1.Text = !MyKey
evolve or die.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform