Search code examples
sql-serverasp-classicadorecordsetreserved-words

Update (ado) recordset with sql reserved word as a column


I am executing the following code:

Set cmdTemp = Server.CreateObject("ADODB.Command")
cmdTemp.CommandType = adCmdText
...
cmdTemp.CommandText = "SELECT email, [Identity], UserName, UserId " & _
                      "  FROM Users WHERE UserId = '" & UserId & "'"

rst.Open cmdTemp, ,adOpenForwardOnly ,adLockOptimistic
rst("Identity") = "101" //ERROR!
rst.Update
rst.Close

It gives this error:

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

/iweb/admin/Users.asp, line 2118

I understand is because the word Identity is reserved in SQL server, but just can't get this to work.

Also tried to replace the line that is throwing the error for:

rst("[Identity]") = "101"

And the result is:

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.

/iweb/admin/Users.asp, line 2118


Solution

  • Try open the recordset with adOpenKeyset CursorTypeEnum

    Look for example here