关于vb用ado对象连接SQL,执行带参数的存储过程
第一种:
Set parm_opt = New ADODB.Parameter
parm_opt.Name = "optcode"
parm_opt.Type = adInteger '参数类型
parm_opt.Size = 4 '参数长度
parm_opt.Direction = adParamInput '参数方向,输入或输出
parm_opt.Value = 1000 '参数的值
cmd.Parameters.Append parm_opt '加入参数
Set parm_std = New ADODB.Parameter
parm_std.Name = "startday"
parm_std.Type = adVarChar
parm_std.Size = 10
parm_std.Direction = adParamInput
parm_std.Value = Format(DTPicker1.Value, "YYYY-MM-DD")
cmd.Parameters.Append parm_std
第二种:
set parm_opt = cmd.creatrparameter( "optcode",adInteger,adParamInput,4,1000
)
cmd.Parameters.Append parm_opt
set parm_std = cmd.creatrparameter( "startday",adVarChar,adParamInput,10,Format(DTPicker1.Value, "YYYY-MM-DD")
)
cmd.Parameters.Append parm_std
########################
为什么用第二种带参数的方式提示出错呢?
[最优解释]
这么写参数,会出人命的.
Set MyComm = Server.CreateObject("ADODB.Command")
with MyComm
.ActiveConnection = conn
.CommandText = "insertCustomer"
.CommandType = 4
.Prepared = true
.Parameters.Append .CreateParameter("@cclass",200,1,24,cclass)
.Parameters.Append .CreateParameter("@cName",200,1,48,cname)
.Parameters.Append .CreateParameter("@csex",130,1,2,csex)
.Parameters.Append .CreateParameter("@cdepname",200,1,100,cdepname)
.Parameters.Append .CreateParameter("@ctel",200,1,48,ctel)
.Parameters.Append .CreateParameter("@cfax",200,1,48,cfax)
.Parameters.Append .CreateParameter("@cmobile",200,1,48,cmobile)
.Parameters.Append .CreateParameter("@caddress",200,1,160,caddress)
.Parameters.Append .CreateParameter("@cqq",200,1,48,cqq)
.Parameters.Append .CreateParameter("@cemail",200,1,160,cemail)
.Parameters.Append .CreateParameter("@cpostcode",200,1,36,cpostcode)
.Parameters.Append .CreateParameter("@cbirthday",200,1,10,ctdate)
.Parameters.Append .CreateParameter("@state",200,1,12,cstate)
.Parameters.Append .CreateParameter("@ctype",200,1,12,ctype)
.Parameters.Append .CreateParameter("@cattach",3,1,4,cattach)
.Parameters.Append .CreateParameter("@csource",200,1,12,csource)
.Parameters.Append .CreateParameter("@ccommend",200,1,48,ccommend)
.Parameters.Append .CreateParameter("@cattention",11,1,1,cattention)
.Parameters.Append .CreateParameter("@cjoindate",200,1,10,jdate)
.Parameters.Append .CreateParameter("@demo",200,1,400,demo)
.Parameters.append .CreateParameter("@returnval",3,2,4)
.Execute
end with