Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return variable question
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00667483
Message ID:
00667527
Views:
20
>>>>I have a stored proc that accepts three parameters - then does a whole lot of processing before doing the final select statement - which I'd like to return as a recordset to VB.
>>>>
>>>>However, the recordset is not being created in VB - I think I may have to declare the select statement as the return 'value' or something ... I've called simple SP's before that only had "select * from whatever" and the recordset was returned without a problem.
>>>>
>>>Maybe your SP returns more than one recordset? Try to run it in QA and see what it returns.
>>
>>The SP only 'returns' one recordset in QA - however, within the SP there are a number of select from ... into table variables. Also, for testing purposes I have a few 'Print @Variable' statements - which do show up in the messages tab in QA - but there is only the one set of records showing up in the grid view.
>
>How do you call that SP from VB?

This code works - the stored procedure I'm calling is just a "select * from whatever" ...
Dim strSQL As String
Dim rsTest As ADODB.Recordset

Set rsTest = New ADODB.Recordset
strSQL = "exec dbo.sp_Test"
       
With rsTest
    .CursorLocation = adUseClient
    .ActiveConnection = objConn
    .CursorType = adOpenStatic
    .LockType = adLockReadOnly
    .Open strSQL ' open the recordset
End With
    
If rsTest.RecordCount > 0 Then
    MsgBox "Records Returned"
End If
 
This one doesn't work - I get VB Error 3704.
Dim strSQL As String
Dim rsTest As ADODB.Recordset

Set rsTest = New ADODB.Recordset
strSQL = "exec dbo.sp_VarianceReport @UserName = wgriffiths, @SortOrder = CostCenter"

       
With rsTest
    .CursorLocation = adUseClient
    .ActiveConnection = objConn
    .CursorType = adOpenStatic
    .LockType = adLockReadOnly
    .Open strSQL ' open the recordset
End With
    
If rsTest.RecordCount > 0 Then   'VB ERROR 3704 HERE
    MsgBox "Records Returned"
End If
 
Al Williams

Anola MB, CANADA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform