Solved

Get output from Sql Stored Procedure VB6

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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Very Large data in MYSQL 7 92
VB.Net Determine if a mapped network drive exists 2 52
Substring works but need to tweak it 14 31
UDP Data Capture Thread Issue 7 30
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 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