How do I call a stored procedure in vb2005

I have a sql2005 express database I am using in a vb2005 application. I have read a bunch and can't seem to find a clear (to me) example of how to call a stored procedure. I have a procedure that runs ok in the query builder, but don't have a clue about how to call it now that it is written. SO.
call the database MYdatabase
call the Stored procedure MYStoredproc.
Any help?
Dave
PS: it dosen't require and values passed to it, its very simple.
[468 byte] By [Dave987654321] at [2007-12-25]
# 1

Maybe this snippet can help:

Dim MyCmd As New OleDbCommand()

Dim Cnxn As New OleDbConnection("ConnectionString")

With MyCmd

.Connection = Cnxn

.CommandType = Data.CommandType.StoredProcedure

.CommandText = "MyStoredproc"

End With

Cnxn.Open()

Dim MyReader As OleDbDataReader = MyCmd.ExecuteReader

While MyReader.Read

Dim Column0Data As String = CStr(MyReader(0))

End While

Cnxn.Close()

DMan1 at 2007-9-3 > top of Msdn Tech,SQL Server,Getting started with SQL Server...
# 2
Thanks, Just what I needed.
dave
Dave987654321 at 2007-9-3 > top of Msdn Tech,SQL Server,Getting started with SQL Server...
# 3
It seems here that its quite easy to set the commandtype to a stored procedure. But i read in a book where they explained how to call stored procedures like this:

  • Create SqlCommand object.

  • Configure it to access a stored procedure by setting the commandtype to stored procedure.

  • Add the parameters that exactly match thoose in the stored procedure itself.

  • Execute.
The bold bullet is represented by this in their example app:

command.Parameters.Add(New SqlParameter(@au_id, authorId))

(command is the SqlCommand created earlier).

I just cant figure out why they are doing this? Is it something you have to do while calling a stored procedure?

Excuse me for possible bad English/American.

JohanFrisell at 2007-9-3 > top of Msdn Tech,SQL Server,Getting started with SQL Server...

SQL Server

Site Classified