VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Howto call different Stored Procedures from VB with or without parameters

by Danilo Priore (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

This a example for call one or more store procedures with different input parameters or without parameters.

Rate Howto call different Stored Procedures from VB with or without parameters


Code:



Public Function ExecuteSP(sProcName As String, 
ParamArray aParams()) As ADODB.Recordset

 Dim cmd As ADODB.Command

 Set cmd = New ADODB.Command

 Set cmd.ActiveConnection = conn

 cmd.CommandText = sProcName

 cmd.CommandType = adCmdStoredProc

 If aParams(0) Is Nothing Then

 
' if NOT use parameters

 Set ExecuteSP = cmd.Execute

 Else

 
 ' if use parameters

 Set ExecuteSP = cmd.Execute(, aParams)

 End If

 Set cmd = Nothing

End Function



Example to call:



Dim rs = ADODB.Recordset


' without params

Set rs = ExecuteSP("sp_selectall",Nothing)


' with params

Set rs = ExecuteSP("sp_find","Danilo","Priore")


' with params without return records

Call ExecuteSP("sp_delete",1234)


' when sp_selectall = "select * from users"

' and sp_find = "select * from user where name=@name and surname=@surname"

' and sp_delete = "delete form user where id=@id"


Download this snippet    Add to My Saved Code

Howto call different Stored Procedures from VB with or without parameters Comments

No comments have been posted about Howto call different Stored Procedures from VB with or without parameters. Why not be the first to post a comment about Howto call different Stored Procedures from VB with or without parameters.

Post your comment

Subject:
Message:
0/1000 characters