LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Excel returning a record set from a stored procedure.

I'm glad it worked. It took me ages to figure out the nocount thing the
first time I ran up against it.

--
Robin Hammond
www.enhanceddatasystems.com


"INTP56" wrote in message
...
Robin,

Thanks for your response. I hate to admit this, but in my haste to create
test procedure I forgot a basic item. When I saw your SQL proc, it
reminded
me of the important item, which is the following line at the top of the
PROC

SET NOCOUNT ON;

Apparently leaving this off screws up ADO with the recordsets. I added
that
line to my procedure (Which I know is supposed to be there all the time)
and
it worked.

One other note, when I showed my colleague, it wouldn't work for him
because
the parameters was always empty. I needed to grant him EXECUTE (and I
included VIEW) permissions in SQL Server for it to work for him. All of us
use integrated security here.

I've attached the final code.

Thanks again, Bob

Sub TestCallSQLSeverPROCwithSET()

' MAKE SURE SQL SERVER PROC HAS SET NOCOUNT ON;
' AND THAT USER HAS EXECUTE/VIEW PERMISSIONS ON PROC

Dim ADODB_Connection As New ADODB.Connection
Dim ADODB_Command As New ADODB.Command
Dim ADODB_Parameters As ADODB.Parameters
Dim ADODB_RecordSet As ADODB.Recordset
Dim i As Integer, j As Integer, k As Integer
Dim RSVariant As Variant

With ADODB_Connection
.ConnectionString = "FILE NAME=C:\UDLFile.udl"
.Open
End With

With ADODB_Command
.ActiveConnection = ADODB_Connection
.CommandType = adCmdStoredProc
.CommandText = "USP_TESTProcSET"
Set ADODB_Parameters = .Parameters
End With

ADODB_Parameters.Refresh
ADODB_Parameters("@SomeString") = "aBcDeFg"

Set ADODB_RecordSet = ADODB_Command.Execute

RSVariant = ADODB_RecordSet.GetRows

i = UBound(RSVariant, 1) - LBound(RSVariant, 1) + 1
j = UBound(RSVariant, 2) - LBound(RSVariant, 2) + 1

With ThisWorkbook.Worksheets(1)
For k = 0 To ADODB_RecordSet.Fields.Count - 1
.Cells(1, k + 1).Value = ADODB_RecordSet.Fields(k).Name
Next k
.Range(.Cells(2, 1), .Cells(j + 1, i)).Value =
WorksheetFunction.Transpose(RSVariant)
End With

Set ADODB_RecordSet = Nothing
Set ADODB_Command = Nothing
ADODB_Connection.Close
Set ADODB_Connection = Nothing

End Sub





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return a stored procedure value to Excel nurkus[_2_] Excel Programming 1 September 6th 06 07:52 AM
Returning a resultset from Oracle Stored Procedure using ADO (VBA) mary Excel Programming 0 December 30th 05 05:26 PM
execute stored procedure from excel maxzsim Excel Worksheet Functions 3 May 11th 05 04:58 PM
Getting stored procedure result to excel mkarja[_2_] Excel Programming 9 March 9th 05 12:56 PM
Run a stored procedure in Excel 2K ArthurB Excel Programming 0 February 26th 04 04:46 PM


All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"