Solved

Stored procedure in VB

Posted on 2001-07-18
2
218 Views
Last Modified: 2012-06-27
I have a stored procedure that I want to call from my VB program. I have two ways of programming it and I want to know the difference. Mostly it is thew way the parameters are set.


**************** Method 1 String Parameters*********  

cmd.CommandText = "AlltestProc " & b & ", '', '', " & f & ", ''"
cmd.CommandType = adCmdStoredProc

********************************************************

+++++++++++++ Method 2 Using Command object ++++++++++++

  cmd.CommandText = "AlltestProc " & b & ", '', '', " & f & ", ''"
  cmd.CommandType = adCmdStoredProc
'  cmd.Parameters.Append cmd.CreateParameter("pint", adInteger, adParamInput, , 1)
'  cmd.Parameters.Append cmd.CreateParameter("pVarchar", adVarChar, adParamInput, 4, "This")
'  cmd.Parameters.Append cmd.CreateParameter("pChar", adChar, adParamInput, 3, "OKY")
'  cmd.Parameters.Append cmd.CreateParameter("pTinyInt", adTinyInt, adParamInput, , 3)
'  cmd.Parameters.Append cmd.CreateParameter("pReturn", adVarChar, adParamOutput, 30, "")
  Set rs = cmd.Execute

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The first method seams to be easier.



0
Comment
Question by:yassin092898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
VincentLawlor earned 50 total points
ID: 6295861
The second method is the best way of doing this. You are specifying the correct types to pass to the Stored Procedure so there will be no ambiguity when they are passed into it.

Vin.
0
 
LVL 5

Expert Comment

by:dgorin
ID: 6295905
You can also use SQL Execute to call your procedure, like

Set rs = con.Execute("EXECUTE sp_name, paramnumber, 'paramtext', moreparams")

This returns a forward-only cursor and may not be applicable for all situations but it's quick and easy.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

695 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