Strange behaviour across environments...

F

fruddy

Hi everyone,
I'm running the following code for an ASP / SQL Server site
on several pages:
--------------------------------------------------------
txtContent = CStr(RSSQL("Content"))
if len(txtContent) > 0 then

txtContent = replace(RSSQL("Content"),"`", "'")

end if
--------------------------------------------------------
Yet I get this error:
Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'replace'

Which is ok as I can error handle with the following code:
--------------------------------------------------------
if len(txtContent) > 0 then

if txtContent <> null then
txtContent = replace(RSSQL("Content"),"`", "'")
end if

end if
--------------------------------------------------------

How can txtContent be null? It's definitely not null, well at least when
I view the query in query analyser. It is to be noted that
RSSQL("Content") is an ntext field.

The query for RSSQL is:
--------------------------------------------------------
SQLHomePage = "Select * from Pages where Title = 'Home page' and Status
= 'Approved'"
Set RSSQL = con.Execute(SQLHomePage)
--------------------------------------------------------

My environment is

IIS 6.0
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)


The part I find strange, is that when this code is being run in another
environment they are not getting this error at all?

I've read that this can be caused by not selecting the ntext fields in a
particular order is that correct? Basically you should select the ntext
fields last.. But why wouldn't this be occuring in all environments? Is
it a SQL version difference?
 
D

Dominique

You should save yourself the agony one and for all... c/;o)

i ALWAYS do something like this:

txtContent = CStr(RSSQL("Content")) & " "

txtContent = replace(txtContent,"`", "'")

^^ this way it never matters if the value is null anyways...

or if you want to do it your way...

txtContent = CStr(RSSQL("Content"))

if TRIM(txtContent) <> "" then
txtContent = replace(txtContent,"`", "'")
end if
^^ use trim instead, and do the replace on the variable that you cast as a
string...NOT the uncast value straight off the recordset :0)

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top