Solved

Get output from Sql Stored Procedure VB6

Posted on 2010-09-14
4
578 Views
Last Modified: 2012-05-10
I am using the attatched code to run a MS SQL stored procedure from VB6

The store procedure that i am running returns @Result (the return can be either 0,1,2,3,4 or 5)

how can i get the return value to VB6 so that i can use it in the program?
Dim cmd As New ADODB.Command
cmd.ActiveConnection = sqlDialler
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "InsertCampaignRecord"

cmd.Parameters.Append cmd.CreateParameter("ID", adChar,adParamInput,20, Telephone)

cmd.Execute

Open in new window

0
Comment
Question by:ict-torquilclark
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33671805
@result: output parameter?
Dim cmd As New ADODB.Command
Dim res As ADODB.Parameter

cmd.ActiveConnection = sqlDialler
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "InsertCampaignRecord"

cmd.Parameters.Append cmd.CreateParameter("ID", adChar,adParamInput,20, Telephone)
set res = cmd.CreateParameter("Result", adInteger,adParamOutput)

cmd.Execute

debug.print res.Value

Open in new window

0
 
LVL 3

Expert Comment

by:deepusreedhar
ID: 33680775
If the Stored Procedure is designed to return an integer, you can do as below.
Dim cmd As New ADODB.Command
Dim intResult as integer
cmd.ActiveConnection = sqlDialler
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "InsertCampaignRecord"
cmd.Parameters.Append cmd.CreateParameter("ID", adChar,adParamInput,20, Telephone)

intResult=cmd.Execute

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33681628
deepusreedhar,

You may want to double check the ADO Execute method.  I suspect you will find the return value is not an integer.  Here is a good tutorial on the subject:
ADO Execute Method
http://www.w3schools.com/ado/met_comm_execute.asp
0
 
LVL 3

Expert Comment

by:deepusreedhar
ID: 33681800
@acperkins:
Thanks for pointing it out. My mistake. We normally use a recordset and then extract the value from recordset.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question