Solved

Get output from Sql Stored Procedure VB6

Posted on 2010-09-14
4
575 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 142

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now