| | |
How to Execute Stored Procedure in VB .. HELP
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2009
Posts: 907
Reputation:
Solved Threads: 167
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...
Then execute the query as you normally would.
Good Luck
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
MyQueryString = "MySp " & MyValue
Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
•
•
•
•
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
•
•
Join Date: Mar 2009
Posts: 907
Reputation:
Solved Threads: 167
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...
>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
Thanks
•
•
•
•
Correct me if I am wrong maheshsayani or anyone else, but using a command object used that way will not return a recorset....
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.
yup please specify waht db you are using and what connection you use, is it either DAO or ADO.
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
•
•
Join Date: Mar 2009
Posts: 907
Reputation:
Solved Threads: 167
•
•
•
•
I am sure you know that the result of command.execute is record set. so may be explain your question more?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Set recordset = command.Execute( RecordsAffected, Parameters, Options )
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
command.Execute RecordsAffected, Parameters, Options
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
Thanks
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
'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
'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
![]() |
Similar Threads
- Execute Stored Procedure From Form (C#)
- exception in executing a stored procedure (ASP.NET)
- How to Execute stored procedures in a javascript or vbscript function (ASP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB4 Help Complier Help
- Next Thread: vb recordset problem
Views: 1970 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





