0

尝试从数据库中获取值并设置为变量,如下所示:

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

我做错了什么?

4

1 回答 1

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
于 2013-11-14T19:28:59.273 回答