• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Stored procedure in VB

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
yassin092898
Asked:
yassin092898
1 Solution
 
VincentLawlorCommented:
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
 
dgorinCommented:
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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now