使用VB6和SQL Server2000
我希望使用rdo连接将值传递给存储过程。
我知道存储过程和rdo连接字符串,但我不知道如何通过rdo连接将参数值传递给存储过程。
尝试过的代码
Dim rsql As rdoQuery
'Set rsql = rdovispay
rsql.rdoParameters ("Storeprocedure1")
rsql.rdoParameters(0).Direction = rdParamReturnValue
rsql(1) = Eid
rsql.Execute有没有人能提供将参数值传递给存储过程的示例代码?
发布于 2011-11-22 13:07:45
来自MSDN:
参数查询只是将用户提供的或应用程序提供的参数替换为普通查询。虽然此查询通常是SELECT语句,但它也可以是INSERT、UPDATE或DELETE查询。下面的示例说明如何使用单个参数编写简单的SELECT查询代码。该查询从Pubs示例数据库中按姓名查找作者。
首先,设置一个使用?标记每个参数的SQL查询。参数标记。
QSQL$ = "SELECT * FROM Authors Au_Lname = ?“
接下来,创建一个rdoQuery对象来管理查询及其参数。
设置PSAuthors = cn.CreateQuery("",QSQL$)
接下来,使用以下代码将用户输入的值(Text1.Text)插入到查询中。
PSAuthors.rdoParameters(0) =文本1.Text
您可以找到完整的页面here
您的代码(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.Executehttps://stackoverflow.com/questions/8216915
复制相似问题