VB系统中调用存储过程的写法
VB系统中使用dimAAWDatabaseAsDatabaseSetAADatabase=DBEngine.OpenDatabase("JJW",False,False,...
VB系统中使用
dim AAWDatabase As Database
Set AADatabase = DBEngine.OpenDatabase("JJW", False, False, "ODBC;DSN=AADSN;DATABSE=AA;UID=;PWD=")
连接ODBC数据源连接
读取数据时
mstrSQL="Select * from person where name='"&name&"' and age="&age&" and sex="&sex
Set RSDynaset = AADatabase.CreateDynaset(mstrSQL)
我现在想把这种直接读取SQL语句改成调用存储过程的方法,输入参数(name,age,sex),输出的为查询结果.
我写成这样错误的:
With AADatabase
.CommandText = "P_Search_MSSQLX_SQL" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = True '要求将SQL命令先行编译
.Parameters.Append .CreateParameter("@name", 3, adParamInput, name)
.Parameters.Append .CreateParameter("@age", 2, adParamInput, age)
.Parameters.Append .CreateParameter("@sex", 2, adParamInput, sex)
End With
Set mDynaset = AADatabase.Execute(1)
===========感觉肯定错误===========
代码应该怎么写,请问?谢谢 展开
dim AAWDatabase As Database
Set AADatabase = DBEngine.OpenDatabase("JJW", False, False, "ODBC;DSN=AADSN;DATABSE=AA;UID=;PWD=")
连接ODBC数据源连接
读取数据时
mstrSQL="Select * from person where name='"&name&"' and age="&age&" and sex="&sex
Set RSDynaset = AADatabase.CreateDynaset(mstrSQL)
我现在想把这种直接读取SQL语句改成调用存储过程的方法,输入参数(name,age,sex),输出的为查询结果.
我写成这样错误的:
With AADatabase
.CommandText = "P_Search_MSSQLX_SQL" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = True '要求将SQL命令先行编译
.Parameters.Append .CreateParameter("@name", 3, adParamInput, name)
.Parameters.Append .CreateParameter("@age", 2, adParamInput, age)
.Parameters.Append .CreateParameter("@sex", 2, adParamInput, sex)
End With
Set mDynaset = AADatabase.Execute(1)
===========感觉肯定错误===========
代码应该怎么写,请问?谢谢 展开
2个回答
展开全部
Dim Cmd As New ADODB.Command
Cmd.CommandType = adCmdStoredProc
Cmd.CommandText = "SendCar"
Cmd.Parameters.Append Cmd.CreateParameter("@DetectNo", adVarChar, adParamInput, 50, ADetect)
Cmd.Parameters.Append Cmd.CreateParameter("@CardNum", adVarChar, adParamInput, 50, Acardnum)
Cmd.Parameters.Append Cmd.CreateParameter("@Detecttype", adVarChar, adParamInput, 50, AdetectType)
Cmd.Parameters.Append Cmd.CreateParameter("@Detectitem", adVarChar, adParamInput, 50, ADetectItem)
Cmd.Parameters.Append Cmd.CreateParameter("@DetectAxiss", adVarChar, adParamInput, 50, AxisList)
Cmd.Parameters.Append Cmd.CreateParameter("@Loginid", adInteger, adParamInput, 50, LoginID)
Cmd.ActiveConnection = Conn
Cmd.Execute
Set Cmd = Nothing
其中Conn是你打开的数据库
Cmd.CommandType = adCmdStoredProc
Cmd.CommandText = "SendCar"
Cmd.Parameters.Append Cmd.CreateParameter("@DetectNo", adVarChar, adParamInput, 50, ADetect)
Cmd.Parameters.Append Cmd.CreateParameter("@CardNum", adVarChar, adParamInput, 50, Acardnum)
Cmd.Parameters.Append Cmd.CreateParameter("@Detecttype", adVarChar, adParamInput, 50, AdetectType)
Cmd.Parameters.Append Cmd.CreateParameter("@Detectitem", adVarChar, adParamInput, 50, ADetectItem)
Cmd.Parameters.Append Cmd.CreateParameter("@DetectAxiss", adVarChar, adParamInput, 50, AxisList)
Cmd.Parameters.Append Cmd.CreateParameter("@Loginid", adInteger, adParamInput, 50, LoginID)
Cmd.ActiveConnection = Conn
Cmd.Execute
Set Cmd = Nothing
其中Conn是你打开的数据库
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询