关于SQL语句,请帮忙!谢谢!

hong0411ren 2003-11-21 06:11:15
Dim CMD As New ADODB.Command
Dim conn As String
Dim rs As ADODB.Recordset
conn = "Provider=SQLOLEDB.1;Password=ehero;Persist Security Info=True;User ID=sa;Initial Catalog=land;Data Source=ehero\ehero"
CMD.CommandText = "select @b=cantonshen from shen where cantonshi=@c"
CMD.Parameters.Append CMD.CreateParameter("@return_value", adInteger, adParamReturnValue)
CMD.Parameters.Append CMD.CreateParameter("@b", adVarChar, adParamInputOutput, 12)
CMD.Parameters.Append CMD.CreateParameter("@c", adVarChar, adParamInput, 12)
CMD("@c") = "太原市"
CMD.ActiveConnection = conn
CMD.Execute
b = CMD("@b")
MsgBox b
执行时出现错误:必须声明变量b,可我已经声明了呀,为什么呢,该怎么改正呢?十分苦恼
...全文
48 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liulangxin 2003-11-21
  • 打赏
  • 举报
回复
给你举个存储过程的例子吧
create proc kkkk
@b int,
@c vchar(20)
as
select @b from shen where cantonshi=@c
zhouqi66 2003-11-21
  • 打赏
  • 举报
回复
阿呆的正确
uffeng 2003-11-21
  • 打赏
  • 举报
回复
CMD.CommandText = "select @b=cantonshen from shen where cantonshi=@c"
如果是有参数的 必须在MSSQL 里面先 做好 一个存储过程

一个简单例子
With cmd
.ActiveConnection = cn
.CommandText = "proc" '存储过程名
.CommandType = adCmdStoredProc
.Parameters.Append cmd.CreateParameter("@b", adInteger, adParamInput, 4, b)'传进参数
.Parameters.Append cmd.CreateParameter("@c", adVarWChar, adParamOutput, 20)'传出参数
.Execute
End With
很容易的 你自己参考着做!!
yoki 2003-11-21
  • 打赏
  • 举报
回复
不能你这样用

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧