How to use a rdo connection in stored procedure

2.3k views Asked by At

Using VB6 and SQL Server 2000

I want to pass the value to stored procedure using rdo connection.

I know stored procedure and rdo connection string, but I don't know how to pass parameter value to stored procedure through rdo connection.

Tried code

Dim rsql As rdoQuery
                'Set rsql = rdovispay
                rsql.rdoParameters ("Storeprocedure1")
                rsql.rdoParameters(0).Direction = rdParamReturnValue
                rsql(1) = Eid
                rsql.Execute

Can anyone provide a sample code for passing the parameter value to stored procedure?

1

There are 1 answers

2
jac On BEST ANSWER

From MSDN:

A parameter query simply substitutes user-supplied or application-supplied parameters into an ordinary query. While this query is usually a SELECT statement, it could be an INSERT, UPDATE, or DELETE query as well. The following example illustrates how to code a simple SELECT query with a single parameter. The query looks up authors by name from the Pubs sample database.

First, set up an SQL query that marks each parameter using the ? parameter marker.

QSQL$ = "SELECT * FROM Authors WHERE Au_Lname = ?"

Next, create an rdoQuery object to manage the query and its parameters.

Set PSAuthors = cn.CreateQuery("",QSQL$)

Next, use the following code to insert the value entered by the user (Text1.Text) into the query.

PSAuthors.rdoParameters(0) = Text1.Text

You can find the complete page here

You code (ODBC syntax) would be modified to:

Dim rsql As rdoQuery
Dim QSQL as string

' if your data source is ODBC then use the ODBC syntax
'QSQL$ = "{ ? = call Storeprocedure1 (?) }"

' if your data source is SQL, then use the SQL syntax
'QSQL$ = "Execute Storeprocedure1 ?"

Set rsql = Connection.CreateQuery("", QSQL$)
rsql.rdoParameters(0).Direction = rdParamReturnValue
rsql(1) = Eid  ' set the input parameter
rsql.Execute