473,386 Members | 2,050 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,386 software developers and data experts.

How to deal with DBNull's

Hi,

I have a strongly typed dataset and when I am trying to process this, one
field is empty ( which is correct at this stage ), but I need to test to see
if it has a value before I try and assign it otherwise it throws an
exception, I have tried the following and a few variations but cant work out
how to test this, any ideas ?

If expRow.DateAuthorised = Nothing Then
Me.AuthorisedDate.Text = expRow.DateAuthorised.Date.ToString

End If


Nov 23 '05 #1
4 1210
Jon
IsDBNull(field) is how to test for nulls

"If foo is nothing" will not work.
"Mr Newbie" <he**@now.com> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a strongly typed dataset and when I am trying to process this, one
field is empty ( which is correct at this stage ), but I need to test to
see if it has a value before I try and assign it otherwise it throws an
exception, I have tried the following and a few variations but cant work
out how to test this, any ideas ?

If expRow.DateAuthorised = Nothing Then
Me.AuthorisedDate.Text = expRow.DateAuthorised.Date.ToString

End If

Nov 23 '05 #2
"Mr Newbie" <he**@now.com> schrieb:
I have a strongly typed dataset and when I am trying to process this, one
field is empty ( which is correct at this stage ), but I need to test to
see if it has a value before I try and assign it otherwise it throws an
exception, I have tried the following and a few variations but cant work
out how to test this, any ideas ?

If expRow.DateAuthorised = Nothing Then
Me.AuthorisedDate.Text = expRow.DateAuthorised.Date.ToString


\\\
If IsDBNull(expRow.DateAuthorized) Then
Me.AutorizedDate.Text = expRow.DateAuthorized.Date.ToString()
End If
///

Alternatively you can use 'If expRow.DateAuthorized Is DBNull.Value
Then...'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #3
Hi,

"Mr Newbie" <he**@now.com> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a strongly typed dataset and when I am trying to process this, one
field is empty ( which is correct at this stage ), but I need to test to
see if it has a value before I try and assign it otherwise it throws an
exception, I have tried the following and a few variations but cant work
out how to test this, any ideas ?

If expRow.DateAuthorised = Nothing Then
If you use a Typed DataSet and assuming that DateAuthorised can be null,
then you will also have the following functions :
expRow.IsDataAuthorisedNull()
expRow.SetDateAuthorisedNull()

So, you need to do:

If ( Not expRow.IsDateAuthorisedNull() ) Then
Me.AuthorisedDate.Text = expRow.DateAuthorised.Date.ToString
End If

Accessing the property when it's DBNull.Value results in an Exception,
because the poperty-get tries to cast the DBNull.Value into a DateTime which
can't be done.

HTH,
Greetings

Me.AuthorisedDate.Text = expRow.DateAuthorised.Date.ToString

End If

Nov 23 '05 #4
Mr Newbie,

I don't know why however I use forever

If Not ExpRow.DataAuthorised Is DbNull.Value then

Just as alternative

Cor
Nov 23 '05 #5

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

Similar topics

8
by: william | last post by:
Hi Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it (string, integer, boolean type field) Thank willia
5
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets...
4
by: Michael Culley | last post by:
Which is better: SomeValue is DBNull or SomeValue == DBNull.Value Thanks, Michael Culley
11
by: Patrick.O.Ige | last post by:
When i try and use this (Where Unit is a column in my Table):- If Unit Is DBNull.Value Then Return "1" Else Return "2" End If I always have 2 returned! Even when Unit is NULL! I want a...
8
by: MattB | last post by:
Hello. I have a vb.net (asp.net) application that uses ado.net datasets. At one point, I need to check a text field in a DataTable to see if there's any text in it before performing text operations...
10
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
6
by: tshad | last post by:
I have a value coming from my Object (or it could also be from a SqlDbReader) where I need to test for DBNull and 0. I tried to do it in one call: if (not (newPosition.ReportsTo is...
6
by: cj | last post by:
in the command window I get: ? result {System.DBNull} : {System.DBNull} I need to check for this in code. I then tested in the command window if result = system.DBNull 'DBNull' is a type...
19
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.