如何将值设置为变量ASP经典?

时间:2013-11-14 19:12:02

标签: asp-classic vbscript

尝试从DataBase获取值并设置为变量,如下所示:

Dim prefferedAgencieUser
Dim agenciePermission

sSql = "SELECT ag.UserTeamLeader "
sSQL = sSQL &  " FROM dbo.BigAgencies ag "
sSQL = sSQL &  " inner join TCL01_cliente cl on cl.preferred_agency=ag.id "
sSQL = sSQL &  " where cl.Cod_cliente = '" & nCodCliente & "'"

Set prefferedAgencieUser = oSelect.ExecuteQuery(sSql)

if prefferedAgencieUser = UserName then
agenciePermission = 1
end if

与数据库的连接运行良好,但我收到了如下错误:

Microsoft VBScript runtime error '800a000d'

Type mismatch

我做错了什么?

1 个答案:

答案 0 :(得分:0)

Dim prefferedAgencieUser 'This is your recordset object
Dim agenciePermission 'This is a variable
Dim sSql 'This is a variable holding your SQL statement

'oSelect - this is your database connection

sSql = "SELECT ag.UserTeamLeader "
sSQL = sSQL &  " FROM dbo.BigAgencies ag "
sSQL = sSQL &  " inner join TCL01_cliente cl on cl.preferred_agency=ag.id "
sSQL = sSQL &  " where cl.Cod_cliente = '" & nCodCliente & "'"

Set prefferedAgencieUser = oSelect.Execute(sSql)

if prefferedAgencieUser.EOF then
    'No record returned from database query
    agenciePermission = 0
ELSE
    'Record(s) returned from database query
    agenciePermission = 1

    UserTeamLeader = prefferedAgencieUser("UserTeamLeader") 'This sets a variable UserTeamLeader to the value returned from the database
end if