Solved

Get output from Sql Stored Procedure VB6

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get the selected ValueMember of Combobox 5 30
Set value of dynamically created checkboxlist 2 31
How to open form using item in Listbox. 8 21
vb.net class 3 11
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

786 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