VB CreateParameter 类型错误
VB Type Error With CreateParameter
所以...我在一个函数中有以下内容,每当调用它时...我都会收到类型错误
Microsoft VBScript runtime error '800a000d'
类型不匹配:'var'
dim conn, cmd, rs
set conn = GetConnection
''' Set the SQL based on request type '''
If isSubscriber = true Then
execSQL = "select stuff from dbo.stuff WHERE field1 = 12" & _
" AND email= @ParameterPwd" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
Else
execSQL = "select stuff from dbo.stuff2 WHERE field1 = 12" & _
" AND email= @ParameterPwd" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
End If
Set cmd = Server.CreateObject("ADODB.Command")
''' Create the command with the appropriate SQL and params '''
With cmd
.activeconnection=conn
.commandtext= execSQL
'Create the parameter (name,type,direction,size,value)
.Parameters.Append .CreateParameter("@ParameterEmail", email)
.Parameters.Append .CreateParameter("@ParameterPwd", pwd)
End With
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open cmd, conn
' Disconnect Recordset '
Set rs.ActiveConnection = Nothing
set GetRecordSetSafeUser = rs
以下行发生错误:
.Parameters.Append .CreateParameter("@ParameterEmail", email)
将该行更改为以下内容:
.Parameters.Append .CreateParameter("@ParameterEmail", adVarChar, adParamInput, Len(email), email)
我收到了这个错误 Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
我不知道为什么会收到此错误。不知道我的脑子是不是炸了。任何帮助将不胜感激!
这里有几个问题:-
var
不是 VBScript 中的关键字。您需要使用 Dim
- 您不能在与声明相同的行上赋值。你需要把它们分开。
- 在将 SQL 分配给
execSQL
时,在行继续字符 _
之前有一个杂散的星号 (*
)。这应该被删除。
- 您为
WHERE
子句中的 email
分配了错误的参数。
- 您不能使用
adVarChar
和 adInputParameter
,因为它们是未知的。您需要用它们的数值替换它们。同样为了完整性和良好实践,您应该在 Command
对象上显式设置 CommandType
属性,以便它不是 "assumed" 类型 adCommandText
。
- 如果您已经在
Command
对象上设置了连接对象,则无法在打开 Recordset
时设置它
这里是 MSDN 链接,可以向您显示参数枚举的数值:-
- 数据类型枚举:https://msdn.microsoft.com/en-us/library/ms675318(v=vs.85).aspx
- 参数方向枚举:https://msdn.microsoft.com/en-us/library/ms678273(v=vs.85).aspx
- 命令类型:https://msdn.microsoft.com/en-us/library/ee266308(v=bts.10).aspx
希望对您有所帮助。
Const adParamInput = 1
Const adVarChar = 200
Const adCmdText = 1
Dim execSQL
execSQL = ""
''' Set the SQL based on request type '''
If isSubscriber = true Then
execSQL = "select stuff from dbo.stuff WHERE field1 = 12" _
" AND email= @ParameterEmail" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
Else
execSQL = "select stuff from dbo.stuff2 WHERE field1 = 12" _
" AND email= @ParameterEmail" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
End If
Set cmd = Server.CreateObject("ADODB.Command")
''' Create the command with the appropriate SQL and params '''
With cmd
.activeconnection=conn
.commandtype = adCmdText
.commandtext= execSQL
'Create the parameter (name,type,direction,size,value)
.Parameters.Append .CreateParameter("@ParameterEmail", adVarChar, adParamInput, Len(email), email)
.Parameters.Append .CreateParameter("@ParameterPwd", adVarChar, adParamInput, Len(pwd), pwd)
End With
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open cmd
所以...我在一个函数中有以下内容,每当调用它时...我都会收到类型错误
Microsoft VBScript runtime error '800a000d'
类型不匹配:'var'
dim conn, cmd, rs
set conn = GetConnection
''' Set the SQL based on request type '''
If isSubscriber = true Then
execSQL = "select stuff from dbo.stuff WHERE field1 = 12" & _
" AND email= @ParameterPwd" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
Else
execSQL = "select stuff from dbo.stuff2 WHERE field1 = 12" & _
" AND email= @ParameterPwd" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
End If
Set cmd = Server.CreateObject("ADODB.Command")
''' Create the command with the appropriate SQL and params '''
With cmd
.activeconnection=conn
.commandtext= execSQL
'Create the parameter (name,type,direction,size,value)
.Parameters.Append .CreateParameter("@ParameterEmail", email)
.Parameters.Append .CreateParameter("@ParameterPwd", pwd)
End With
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open cmd, conn
' Disconnect Recordset '
Set rs.ActiveConnection = Nothing
set GetRecordSetSafeUser = rs
以下行发生错误:
.Parameters.Append .CreateParameter("@ParameterEmail", email)
将该行更改为以下内容:
.Parameters.Append .CreateParameter("@ParameterEmail", adVarChar, adParamInput, Len(email), email)
我收到了这个错误 Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
我不知道为什么会收到此错误。不知道我的脑子是不是炸了。任何帮助将不胜感激!
这里有几个问题:-
var
不是 VBScript 中的关键字。您需要使用Dim
- 您不能在与声明相同的行上赋值。你需要把它们分开。
- 在将 SQL 分配给
execSQL
时,在行继续字符_
之前有一个杂散的星号 (*
)。这应该被删除。 - 您为
WHERE
子句中的email
分配了错误的参数。 - 您不能使用
adVarChar
和adInputParameter
,因为它们是未知的。您需要用它们的数值替换它们。同样为了完整性和良好实践,您应该在Command
对象上显式设置CommandType
属性,以便它不是 "assumed" 类型adCommandText
。 - 如果您已经在
Command
对象上设置了连接对象,则无法在打开Recordset
时设置它
这里是 MSDN 链接,可以向您显示参数枚举的数值:-
- 数据类型枚举:https://msdn.microsoft.com/en-us/library/ms675318(v=vs.85).aspx
- 参数方向枚举:https://msdn.microsoft.com/en-us/library/ms678273(v=vs.85).aspx
- 命令类型:https://msdn.microsoft.com/en-us/library/ee266308(v=bts.10).aspx
希望对您有所帮助。
Const adParamInput = 1
Const adVarChar = 200
Const adCmdText = 1
Dim execSQL
execSQL = ""
''' Set the SQL based on request type '''
If isSubscriber = true Then
execSQL = "select stuff from dbo.stuff WHERE field1 = 12" _
" AND email= @ParameterEmail" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
Else
execSQL = "select stuff from dbo.stuff2 WHERE field1 = 12" _
" AND email= @ParameterEmail" & _
" AND password= @ParameterPwd" & _
" AND EndDate >= GETDATE() "
End If
Set cmd = Server.CreateObject("ADODB.Command")
''' Create the command with the appropriate SQL and params '''
With cmd
.activeconnection=conn
.commandtype = adCmdText
.commandtext= execSQL
'Create the parameter (name,type,direction,size,value)
.Parameters.Append .CreateParameter("@ParameterEmail", adVarChar, adParamInput, Len(email), email)
.Parameters.Append .CreateParameter("@ParameterPwd", adVarChar, adParamInput, Len(pwd), pwd)
End With
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open cmd