Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Connection String to SQL to run Stored Procedure

Does anyone have samle code to connect and run a stored Proc on SQL Server?
I have the Server name. It is added to my ODBC and connection is good, but
to simply connect and run a sp from Excel is driving me crazy.
Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Connection String to SQL to run Stored Procedure

This can drive you mad!!

Try recording a macro while using the menu options Data-Import External
Data and using the appropriate connections etc. It should give you a
starter template if not the whole answer.

--
Cheers
Nigel



"Carl" wrote in message
news:t7Hcf.65$7B.48@fed1read02...
Does anyone have samle code to connect and run a stored Proc on SQL

Server?
I have the Server name. It is added to my ODBC and connection is good, but
to simply connect and run a sp from Excel is driving me crazy.
Thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Connection String to SQL to run Stored Procedure

Hi
This from code samples with "Excel 2002 VBA" by Stephen Bullen et al

Public Sub SavedQuery()

Dim objField As ADODB.Field
Dim rsData As ADODB.Recordset
Dim lOffset As Long
Dim szConnect As String

' Create the connection string.
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Files\Northwind.mdb;"

' Create the Recorset object and run the query.
Set rsData = New ADODB.Recordset
rsData.Open "[Sales By Category]", szConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdTable

' Make sure we got records back
If Not rsData.EOF Then
' Add headers to the worksheet.
With Sheet1.Range("A1")
For Each objField In rsData.Fields
.Offset(0, lOffset).Value = objField.Name
lOffset = lOffset + 1
Next objField
.Resize(1, rsData.Fields.Count).Font.Bold = True
End With
' Dump the contents of the recordset onto the worksheet.
Sheet1.Range("A2").CopyFromRecordset rsData
' Close the recordset
rsData.Close
' Fit the column widths to the data.
Sheet1.UsedRange.EntireColumn.AutoFit
Else
MsgBox "Error: No records returned.", vbCritical
End If

Set rsData = Nothing

End Sub

regards
Paul

Reply
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
Excel Connection to SQL 2007 can't find stored procedure message SaveTheMonarchButterflies Excel Discussion (Misc queries) 0 November 10th 08 03:58 PM
execute stored procedure from excel maxzsim Excel Worksheet Functions 3 May 11th 05 04:58 PM
execute stored procedure Mark Goldin Excel Programming 3 April 7th 04 03:03 PM
Run a stored procedure in Excel 2K ArthurB Excel Programming 0 February 26th 04 04:46 PM
Execute stored procedure using DAO sapta wijaya Excel Programming 0 September 29th 03 04:24 AM


All times are GMT +1. The time now is 12:14 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"