How to Execute Stored Procedure in VB .. HELP

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2009
Posts: 1
Reputation: koolsamjust4u is an unknown quantity at this point 
Solved Threads: 0
koolsamjust4u koolsamjust4u is offline Offline
Newbie Poster

How to Execute Stored Procedure in VB .. HELP

 
0
  #1
May 10th, 2009
Hi Friends .. need a small help can anyone help me in showing how to call a stored procedure which returns a recordset .. yea i need to pass one parameter also for getting that required data .. thanks in advance..


Sameer
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 907
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 167
vb5prgrmr vb5prgrmr is offline Offline
Posting Shark

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #2
May 10th, 2009
Just use a recordset object as you normally would. i.e. say your SP has a name of MySP and it accepts one parameter. So you query string would be something like...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. MyQueryString = "MySp " & MyValue
Then execute the query as you normally would.

Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 45
Reputation: maheshsayani is an unknown quantity at this point 
Solved Threads: 2
maheshsayani's Avatar
maheshsayani maheshsayani is offline Offline
Light Poster

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #3
May 11th, 2009
Originally Posted by koolsamjust4u View Post
Hi Friends .. need a small help can anyone help me in showing how to call a stored procedure which returns a recordset .. yea i need to pass one parameter also for getting that required data .. thanks in advance..


Sameer

Hi Sameer,

If you are using VB6 then u need to use Command object.

Please see the below example
Dim mobjConn As ADODB.Connection
Dim mobjCmd As ADODB.Command
Dim mobjRst As ADODB.Recordset

Set mobjCmd = New ADODB.Command

mobjCmd.CommandType = adCmdStoredProc

mobjCmd.Parameters.Append mobjCmd.CreateParameter("<Param Name> ", <Param Datatype>, <Param Type>, ,<Value>)

mobjCmd.CommandText = strSPName
mobjCmd.Execute

Please let me know if you have any issues

Mahesh B Sayani
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 907
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 167
vb5prgrmr vb5prgrmr is offline Offline
Posting Shark

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #4
May 11th, 2009
Correct me if I am wrong maheshsayani or anyone else, but using a command object used that way will not return a recorset....

>need a small help can anyone help me in showing how to call a stored procedure which returns a recordset

Hence, my suggestion to use a recordset object...
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: samir_ibrahim is on a distinguished road 
Solved Threads: 16
samir_ibrahim's Avatar
samir_ibrahim samir_ibrahim is offline Offline
Junior Poster

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #5
May 18th, 2009
Originally Posted by vb5prgrmr View Post
Correct me if I am wrong maheshsayani or anyone else, but using a command object used that way will not return a recorset....
I am sure you know that the result of command.execute is record set. so may be explain your question more?

As I did not understand the PO question, I did not on which back end he talking about. does he mean a SP in SQL Server or a normal function in vb he is calling it stored procedure.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 43
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #6
May 18th, 2009
yup please specify waht db you are using and what connection you use, is it either DAO or ADO.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 907
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 167
vb5prgrmr vb5prgrmr is offline Offline
Posting Shark

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #7
May 18th, 2009
Originally Posted by samir_ibrahim View Post
I am sure you know that the result of command.execute is record set. so may be explain your question more?
Yes, I do realize that if you...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set recordset = command.Execute( RecordsAffected, Parameters, Options )
but the way maheshsayani used it...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. command.Execute RecordsAffected, Parameters, Options
does not return a recordset, hence my post...

As for understanding the OP's origional Q see post #1 above. It seems pretty strait forward to me...

Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: Tassilo is an unknown quantity at this point 
Solved Threads: 0
Tassilo Tassilo is offline Offline
Newbie Poster

Re: How to Execute Stored Procedure in VB .. HELP

 
0
  #8
Jun 18th, 2009
'ADO is a DataEnvironment
'conGeneral is a DEConnection (to connect to the SQL Server)

'on the form dim the recordset

Dim rsRecord As New ADODB.Recordset

'then call the Stored Procedure "pro_StoredProc" with the parameter
With rsRecord
If .state = adStateOpen Then .Close
'
' set propertie of recordset (don't need if only read records)
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
' open recordset with a numeric Parameter
.Open ("{Call pro_StoredProc(" & Parameter & ")}"), ADO.conGeneral
' open recordset with a String Parameter
.Open ("{Call pro_StoredProc('" & Parameter & "')}"), ADO.conGeneral
'then go on as usual
Do Until .EOF
'read the record
.MoveNext
Loop

End With
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1970 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC