ADODB/IsDBNull Problem

J

Jim

I am having a problem with the IsDBNull function. When it checks what
type of value is contained in the parameter that is passed to it, it
does not successfully determine that it has a DBNull value. If I
access the value of what I am going to pass to the IsDBNull function
before I call the IsDBNull function then it does successfully
determine that it has a DBNull value. Below is a page that I am using
to test. Note: that the value for the column copy_text is null in
this specific case.

<%@ Page %>
<%@ Import namespace="ADODB" %>
<%
Dim Conn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim copy As String

Conn = New ADODB.Connection
Conn.Open("DSN=xxx;uid=xxx;pwd=xxx;")

adoRS = New ADODB.Recordset

sql = "select copy_text from printone_copy where ach_id = 43887"
adoRS.Open(sql, conn)

If Not adoRS.eof Then
'dim objtest as Object
'objtest = adoRS.Fields("copy_text").Value
if IsDBNull(adoRS.Fields("copy_text").Value) then
copy = "No Value"
else
copy = adoRS.Fields("copy_text").Value
end if
Else
copy = "No Value"
End If
adoRS.Close()

Response.Write(copy)
%>

If I uncomment the two lines before the IsDBNull function call then
the IsDBNull function correctly returns true, otherwise it returns
false. And when it returns false I get an error as it tries to put
DBNull into the string variable copy. Any help on this would be much
appreciated.

Jim
 
C

Cablewizard

I have not seen it behave like this before.
What type of database are you connecting to?
You may need to explicitly change either the connection or recordset parameters.
But at this point I don't know what you would need to change, cause as best I
can tell it should be working.

Gerald
 
J

Jim Bailey

I am connecting to a MS SqlServer 2000 DB. And I am using ADODB because
we are doing a port of an asp application to asp.net and want to do a
minimal amount of code change to start with. I have not investigated
changing connection or recordset parameters yet. I was hoping that
someone else had run into this problem before me. I will see what
progress I can make with changing the parameters.

Jim
 
C

Cablewizard

ah, hmm. well, ADO works best with MS SQL 2K, so I am stumped.
Maybe it has something to do with ASP?
I still use ADO a lot instead of ADO.Net for similar reasons.
But I don't do much in ASP and I have yet to encounter that particular problem
with normal apps. wish I could help.

Gerald
 

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

Top