Solved

Get output from Sql Stored Procedure VB6

Posted on 2010-09-14
4
574 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
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
@acperkins:
Thanks for pointing it out. My mistake. We normally use a recordset and then extract the value from recordset.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB.net PaintEventArgs Handling. 10 26
Showdialog 8 20
Visual Studio 2005 text editor 10 18
Copy/Clone an object. 9 10
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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
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…

744 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

9 Experts available now in Live!

Get 1:1 Help Now