how to call a SQL Server stored procedure in VB using ADO

Could someone please provide a snippet of code on how I would call a stored procedure in SQL Server using VB and the ADO command object. A bried comment of each step would be very, very helpful.

Not sure how to tie everything together.

Thanks in advance.

LVL 13
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
Here is one example.

 Dim objConn, objCmd, objParam
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=macdb;uid=test;pwd=test"
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.CommandText = "sp_sel_no_authors"
objCmd.CommandType = adCmdStoredProc
objcmd.ActiveConnection = objConn
Set objParam = objCmd.CreateParameter ("@count_authors",adInteger,adParamOutput,4)
objCmd.Parameters.Append objParam

you can also take the full details about this issue from below link.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ashish PatelCommented:
Look at the code snippet
'ConnectionObject is the connection object to database
    Set commnd = New ADODB.Command
    commnd.ActiveConnection = ConnectionObject
    commnd.CommandType = 4
    commnd.CommandTimeout = 180
    commnd.CommandText = "Insertvalues"
'@EMPID is the SP parameter name
'adInteger is the Type of @EMPID (Int)
'adParamInput is to say that this is input parameter
'4 is the length for the type
'var_EmpID is the varaible in my vb code which contains value to be passed
    commnd.Parameters.Append commnd.CreateParameter("@EmpID", adInteger, adParamInput, 4, var_EmpID)
    commnd.Parameters.Append commnd.CreateParameter("@Name", adVarChar, adParamInput, 50, var_Name)
    commnd.Parameters.Append commnd.CreateParameter("@FirstName", adVarChar, adParamInput, 100, var_FirstName)

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.