Solved

Stored procedure in VB

Posted on 2001-07-18
2
212 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
2 Comments
 
LVL 4

Accepted Solution

by:
VincentLawlor earned 50 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now