List Info

Thread: RE: VB.NET test for DBNull




RE: VB.NET test for DBNull
user name
2007-06-15 17:45:37
This is equivalent to what I and a couple other suggested:

    If FieldOfTypeDate = DBNull.Value Then

or in other words,

    If myDataReader("MyFieldOfTypeDate") =
DBNull.Value Then

Are you saying this didn't work where
myDataReader.IsDBNull(ordinal)
did?

If you use the IsDBNull method, make sure you don't
hard-code the column
ordinal.

--Peter


> -----Original Message-----
> From: John Warner [mailto:johnjwarner.com] 
> Sent: Friday, June 15, 2007 9:19 AM
> To: aspnetaspadvice.com
> Subject: [aspnet] RE: VB.NET test for DBNull
> 
> 
> Thanks to all who have replied. After spending the
night in 
> the docs (they
> get worse with each version of VS) I think I've found
the 
> solution at least
> for a DataReader object. The dr method IsDBNull(column

> ordinal). This is
> supposed (I'm just back at my desk this morning)  to
work for all the
> strongly typed dr.get<type> methods. 
> 
> John Warner
> 
> 
> 
> 
> > -----Original Message-----
> > From: lhoughrogers.com [mailto:lhoughrogers.com] 
> > Sent: Friday, June 15, 2007 7:12 AM
> > To: aspnetaspadvice.com
> > Subject: [aspnet] RE: VB.NET test for DBNull
> > 
> > 
> > Try:
> > 
> > If NOT myDataReader.item("Expr14") is
dbnull.value then
> > 
> > HTH
> > 
> > Larry
> > 
> > 
> > ----- Original Message ----
> > From: tom m <timallardmsn.com>
> > To: aspnetaspadvice.com
> > Sent: Friday, June 15, 2007 12:04:32 AM
> > Subject: [aspnet] RE: VB.NET test for DBNull
> > 
> > 
> > I've used a different syntax ... If
(myDataReader.Item("Expr14") =
> > System.DbNull.Value) Then ...
> > 
> > tom mallard
> >    .net web applications
> >       consumer product design
> > 
> > -----Original Message-----
> > From: Duane [mailto:starwaycorpcomcast.net] 
> > Sent: Thursday, June 14, 2007 4:39 PM
> > To: aspnetaspadvice.com
> > Subject: [aspnet] RE: VB.NET test for DBNull
> > 
> > If IsDBNull(myDataReader.Item("Expr14"))
Then  'checks if the 
> > MapURL is Null
> > 
> >    'do nothing
> > Else
> > 
> > That should work for nulls in VB.NET
> > 
> > htt
p://msdn2.microsoft.com/en-us/library/tckcces5(VS.80).as
px
> > 
> > 
> > -----Original Message-----
> > From: John Warner [mailto:johnjwarner.com]
> > Sent: Thursday, June 14, 2007 6:14 PM
> > To: aspnetaspadvice.com
> > Subject: [aspnet] RE: VB.NET test for DBNull
> > 
> > 
> > I thought I explained this, though not well
enough, the 
> > Source is not SQL Server, it is not a file on any
computer I 
> > can reach, it is an ODBC
> > (Transoft) data source on a Unix server. DTS will
not work, 
> > it can't see the data source, I barely can. That
is why I was 
> > asking about VB.NET solutions. I find it amazing
that 
> > Microsoft knowing well over half the development
in VB or C# 
> > is targeting databases and they provide no good
means to test 
> > for NULL in .NET when once they did provide a
method. 
> > 
> > But thank you for trying.
> > 
> > Any one ever have to deal with adding data to a
database in 
> > code before, how did you handle it?
> > 
> > John Warner
> > 
> > 
> > > -----Original Message-----
> > > From: Johnson, Peter
[mailto:Peter.Johnsonmercer.com]
> > > Sent: Thursday, June 14, 2007 4:56 PM
> > > To: aspnetaspadvice.com
> > > Subject: [aspnet] RE: VB.NET test for DBNull
> > > 
> > > 
> > > If you don't need user interaction, you might
skip VB.NET 
> > altogether 
> > > and write SQL Server DTS import
packages/scripts.
> > > 
> > > There are nulls in a database context
(DBNull) and nulls 
> in a .NET 
> > > context (Nothing in VB.NET), which might be
part of the 
> > > misunderstanding. If you're selecting nulls
out of the first SQL 
> > > Server database, you might try this:
> > > 
> > > If FieldOfTypeDate = DBNull.Value Then
> > > 
> > > Although, if it's just going back into SQL
Server, 
> depending on how 
> > > you're doing it (manually building SQL code
inline? bad idea... 
> > > parameters?), you may not need to do anything
special for 
> > nulls going 
> > > right back into the other database.
> > > 
> > > --Peter
> > > 
> > > 
> > > > -----Original Message-----
> > > > From: John Warner [mailto:johnjwarner.com]
> > > > Sent: Thursday, June 14, 2007 4:46 PM
> > > > To: aspnetaspadvice.com
> > > > Subject: [aspnet] VB.NET test for
DBNull
> > > > 
> > > > 
> > > > How do I test a field coming in (not
user supplied in this
> > > > case) for a NULL
> > > > before inserting it into my SQL Server
database? I have 
> > seen on the 
> > > > web the examples using string values,
but what of the other data
> > > types such as
> > > > decimal or datetime? In VB.NET (v 1.1)
the IS operator is not 
> > > > allowed in the following:
> > > > 
> > > > Dim MyNull as System.Data.DBNull
> > > > 
> > > > If FieldOfTypeDate Is MyNull   <
errors out 'Is' not allowed
> > > >  also "=" is not allowed. So
how does one test for null when the
> > > > data type is not a string?
> > > > 
> > > > Is there any REAL substitute for the old
IsNull() function from
> > > > classic VB?
> > > > 
> > > > What I'm trying to do is move some data
from one database into
> > > > another, both are not SQL Server only
the target 
> database is.  I 
> > > > need to check for
> > > > Null before creating my Insert
statement, but testing results 
> > > > in an error
> > > > if the incoming data type is anything
other then a 
> > > > string/char. For example
> > > > if the old database has  nothing in a
date field, I need to 
> > > > insert a NULL
> > > > into SQL Server, but I can't seem to
test for this 
> > condition without
> > > > creating an error. 
> > > > 
> > > > How do those of you more experienced
then me deal with NULL?
> > > > 
> > > > Thanks,
> > > > 
> > > > John Warner

                                                         __


------------------------------------------------------------
-
This e-mail and any attachments may be confidential or
legally privileged. If you received this message in error or
are not the intended recipient, you should destroy the
e-mail message and any attachments or copies, and you are
prohibited from retaining, distributing, disclosing, or
using any information contained herein.  Please inform us of
the erroneous delivery by return e-mail. Thank you for your
cooperation.
------------------------------------------------------------
-

FE01

--- List Settings ---
http://aspadvice.com/list
s/


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )