473,385 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ADODB/IsDBNull Problem

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
Jul 21 '05 #1
4 3426
That does seem kind of strange.

However, why are using ADO and not ADO.NET?

"Jim" <jr*********@yahoo.com> wrote in message
news:ae**************************@posting.google.c om...
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

Jul 21 '05 #2
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

"Jim" <jr*********@yahoo.com> wrote in message
news:ae**************************@posting.google.c om...
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

Jul 21 '05 #3
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #4
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

"Jim Bailey" <jr*********@yahoo.com> wrote in message
news:Oi**************@TK2MSFTNGP11.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: jim | last post by:
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid If IsDBNull(Clinics.Clinics.Item(A).Workphone) The <other code End I Clinics.Clinics is a dataset that...
5
by: luna | last post by:
how to i use isdbnull on two tables ? im pulling out the data with a stored procedure like this :- CREATE PROCEDURE search @search varchar(8) AS
3
by: Paul D. Fox | last post by:
I have this code snippet below where I'm loading all the labels based upon the retrieved record from the DataReader. Unfortunatley, some of the values are null, so I can't explicitly set the...
4
by: Edwinah63 | last post by:
Hi guys, i have a collection containing the values and metadata about a current record. i build it by looping through the recordset as follows: Public Function NoNull(ByVal Value As Object)...
4
by: Jim | last post by:
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...
6
by: Wonder | last post by:
We have a VB.NET project with a reference to ADO 2.5 When I open it on my machine, I get the following build error: "The referenced component 'ADODB' has an updated custom wrapper available." ...
4
by: sck10 | last post by:
Hello (converting from vb to c#), Is there a way to test the value of null of a particular field of a dataset from SQL Server? I am going through a dataset and trying to determine if the value...
4
by: Brad Isaacs | last post by:
I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005 Working with DataSet creating a Data Access Layer via VS 2005. My error is when the code that is prewritten by VS 2005 Casts...
2
by: =?Utf-8?B?TWlrZSBPS0M=?= | last post by:
VB 2005 All developers face this issue; so I'm sure Microsoft was a solution for it. What is the built in method to check DBNull in a recordset field? NOT a typed dataset. I don't want to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.