Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How to use Excel VBA program to execute SQL SERVER stored procedur

Dear all,
I want to use Excel VBA program to execute SQL SERVER stored procedure.
But error occurs."Error sql statement ,except Insert update delete procedure"
How can I correct this ? thanks

code:
sqlstr = "exec stored_proc_name('Parameter')"
Sqldb.Execute sqlstr
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default How to use Excel VBA program to execute SQL SERVER stored procedur

Hi, in my opinion, you have to initialise the Sqldb with valid
authentication, connection string/DSN etc.... and then try running the
statement.

"Arron" wrote:

Dear all,
I want to use Excel VBA program to execute SQL SERVER stored procedure.
But error occurs."Error sql statement ,except Insert update delete procedure"
How can I correct this ? thanks

code:
sqlstr = "exec stored_proc_name('Parameter')"
Sqldb.Execute sqlstr

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default How to use Excel VBA program to execute SQL SERVER stored procedur

I have some sample code that executes sp_dboption to set quoted identifiers
on for Pubs, then displays all set options for Pubs database. Hope it helps
some.

Sub testSP()

Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset

cn.Provider = "sqloledb"
cn.Properties("Data Source").Value = "ServerName"
cn.Properties("Initial Catalog").Value = "northwind"
cn.Properties("Integrated Security").Value = "SSPI"
cn.Open

cmd.ActiveConnection = cn
cmd.CommandText = _
"sp_dboption ('pubs','quoted identifier','on')"
cmd.CommandType = adCmdStoredProc

Set rs = cmd.Execute

cmd.CommandText = "sp_dboption ('pubs')"

Set rs = cmd.Execute

rs.MoveFirst

Do While Not rs.EOF
For Each f In rs.Fields
Debug.Print f.Name & vbTab & f.Value
Next
rs.MoveNext
Loop

rs.Close
cn.Close

End Sub



--
urkec


"Arron" wrote:

Dear all,
I want to use Excel VBA program to execute SQL SERVER stored procedure.
But error occurs."Error sql statement ,except Insert update delete procedure"
How can I correct this ? thanks

code:
sqlstr = "exec stored_proc_name('Parameter')"
Sqldb.Execute sqlstr

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
execute stored proc in Excel William Excel Programming 1 February 5th 06 10:52 PM
Run SQL Server stored procedure in Excel macro Peder Myhre Excel Programming 1 November 8th 05 10:54 PM
execute stored procedure from excel maxzsim Excel Worksheet Functions 3 May 11th 05 04:58 PM
Excel files stored on a different server Sri Excel Discussion (Misc queries) 0 February 4th 05 11:25 AM
Execute a query against an excel doc and a sql server db Rick[_14_] Excel Programming 1 August 30th 03 02:50 PM


All times are GMT +1. The time now is 05:07 PM.

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

About Us

"It's about Microsoft Excel"