Home > Software design >  Why does an ADODB.Command Object throw - "Invalid use of Null: 'replace'"
Why does an ADODB.Command Object throw - "Invalid use of Null: 'replace'"

Time:01-18

I have some code that was using an ADODB.Recordset object to query a MariaDb database. In my query I am using coalesce such as this -

SELECT COALESCE(offers_owner.description, offers.description) AS description FROM
offers_owner LEFT JOIN websites on offers_owner.website_id = websites.id LEFT JOIN offers on
offers_owner.offer_id = offers.id WHERE offers_owner.id = 401

and in my code I have this -

If Not IsNull(rs("description")) or rs("description") <> "" Then
    response.write "<p clear" & chr(34) & "><br />" & replace(replace(rs("description"),"company_name",session("company")),"company_city",session("city2")) & "<br /><br /></p>" & vbcrlf
end if

This works fine, and outputs as need be.

But, as soon as I switch to using an ADODB.Command object, I get an "invalid use of null". If I remove the conditional If Then, it does not throw and error.

Any idea as to why?

Thank you.

I tried to limit the conditionals in the IF Then statement

CodePudding user response:

The way I solved this was to assign the value of the field in question to a variable, such as

description = myRS("description").value

if not isNULL(description) and description <> "" Then replace(description,"xyz","abc") end if

CodePudding user response:

Try replacing IsNull with IsDbNull to check if the parameter evaluates to DBNull.

  • Related