呸,vbscript.
我正在试图弄清楚如何使这个陈述起作用:
if (not rsObject("columnNameThatDoesntExist") is nothing) then
' do some stuff
end if
' else do nothin
Run Code Online (Sandbox Code Playgroud)
其中rsObject是一个RecordSet,而columnNameThatDoesntExist是......你知道吗.我正在寻找类似rsObject.Columns.Contains(string)的东西.但当然找不到它.
编辑:看起来像循环rsObject.Fields是一个选项,这是唯一的方法吗?
我相信你有理由,但是如果你不知道你从数据库回调了哪些字段,你总是可以使用On Error Resume Next和On Error Goto 0来忽略抛出的错误.对我来说似乎是一种糟糕的方式,但它会起作用
blnItWasntThere = True
On Error Resume Next
If (rsObject("columnNameThatDoesntExist") <> "") Then
blnItWasntThere = False
...
...
...
End If
On Error Goto 0
If blnItWasntThere Then
'handle this error'
End If
Run Code Online (Sandbox Code Playgroud)
但话说回来,我想你会更加担心你要回来的神秘记录.
或者自己动手
Function ColumnExists(objRS, Column)
Dim blnOutput, x
blnOutput = True
On Error Resume Next
x = objRS(Column)
If err.Number <> 0 Then blnOutput = False
On Error Goto 0
ColumnExists = blnOutput
End Function
Run Code Online (Sandbox Code Playgroud)