使用CreateParameter的VB类型错误

时间:2015-09-01 06:55:12

标签: asp-classic

所以...我在一个函数中有以下内容,每当它被调用时......我得到一个类型错误

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.

我不知道为什么我会收到此错误。不确定我的大脑是否被炒过。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

这里有几个问题: -

  1. var不是VBScript中的关键字。您需要使用Dim
  2. 您不能在声明的同一行指定值。你需要将它们分开。
  3. 在将SQL分配给*时,您的行继续符_之前有一个迷路星号(execSQL)。这应该删除。
  4. 您正在为email子句中的WHERE分配错误的参数。
  5. 您无法使用adVarCharadInputParameter,因为这些是未知的。您需要用它们的数值替换它们。同样,为了完整性和良好实践,您应该在CommandType对象上明确设置Command属性,以使其不被假定为#34;属于adCommandText
  6. 如果您已在Recordset对象上设置了Command,则无法在打开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 时设置连接对象
  7. 以下是MSDN链接,用于显示参数枚举的数值: -

    希望有所帮助。

    itemnumber = parameter.AuxProperty.ContainsKey("art_nr")?parameter.AuxProperty["art_nr"].ToString():String.Empty;