Tools Links Login

Howto call different Stored Procedures from VB with or without parameters

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

Original Author: Danilo Priore

Code


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"


About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 104 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.