This snippet will allow you to check whether a certain column exists in a database table or not. Useful when you're coding against a database which schema you don't fully know. Just change the name of the column you're looking for (nameToCheck), the Connection String and the SQL SELECT statement, the bold items in this snippet.
<%
Dim oField ' As ADODB.Field
Dim oRecordset ' As ADODB.Recordset
Dim oConn ' As ADODB.Connection
Dim nameToCheck
Dim nameExists
' The column name you're looking for
nameToCheck = "ID"
nameExists = false
' Create connection
Set oConn = Server.CreateObject("ADODB.Connection"
oConn.Open "YourConnectionString"
Set oRecordset = oConn.Execute("SELECT * FROM YourTable"
For Each oField In oRecordset.Fields
If oField.Name = nameToCheck Then
nameExists = True
Exit For
End If
Next
oRecordset.Close()
oConn.Close()
Set oConn = Nothing
Set oRecordset = Nothing
Response.Write("Field " & nameToCheck & " found: " & nameExists)
%>