Link to home
Start Free TrialLog in
Avatar of yassin092898
yassin092898

asked on

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.



ASKER CERTIFIED SOLUTION
Avatar of VincentLawlor
VincentLawlor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dgorin
dgorin

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.