0

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?

4

1 回答 1

0

来自 MSDN:

参数查询只是将用户提供或应用程序提供的参数替换为普通查询。虽然此查询通常是 SELECT 语句,但它也可以是 INSERT、UPDATE 或 DELETE 查询。以下示例说明了如何使用单个参数编写简单的 SELECT 查询。该查询按姓名从 Pubs 示例数据库中查找作者。

首先,设置一个使用 ? 标记每个参数的 SQL 查询。参数标记。

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

接下来,创建一个 rdoQuery 对象来管理查询及其参数。

设置 PSAuthors = cn.CreateQuery("",QSQL$)

接下来,使用以下代码将用户输入的值 (Text1.Text) 插入到查询中。

PSAuthors.rdoParameters(0) = Text1.Text

你可以在这里找到完整的页面

您的代码(ODBC 语法)将被修改为:

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
于 2011-11-22T05:07:44.603 回答