473,473 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to trap DBNull?

Hi all,

I have a date field in a temp table as part of a DataSet. In some records
the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....

Thanks,

Claus
Nov 21 '05 #1
6 3796
"cjobes" <cj****@nova-tech.org> wrote in news:OAvLiZa1EHA.324
@TK2MSFTNGP10.phx.gbl:
Hi all,

I have a date field in a temp table as part of a DataSet. In some records
the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....

If dtTemp("When") is system.dbnull.value then
Msgbox("oops dbnull!")
end if

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value of
another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the
record is already there it would replace the data) and there isn't anything
like "change" or "replace". How can I do this?

Thanks,

Claus
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"cjobes" <cj****@nova-tech.org> wrote in news:OAvLiZa1EHA.324
@TK2MSFTNGP10.phx.gbl:
Hi all,

I have a date field in a temp table as part of a DataSet. In some records the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....

If dtTemp("When") is system.dbnull.value then
Msgbox("oops dbnull!")
end if

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #3
You Need to Edit the ItemArray associated with that row.

Also Rows.Add does work in a round about way

Dim DT As New Data.DataTable
Dim DR As Data.DataRow
DR = DT.NewRow
DR.ItemArray(0) = "Test"
DR.ItemArray(1) = "Test2"
DT.Rows.Add(DR)
"cjobes" wrote:
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value of
another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the
record is already there it would replace the data) and there isn't anything
like "change" or "replace". How can I do this?

Thanks,

Claus
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"cjobes" <cj****@nova-tech.org> wrote in news:OAvLiZa1EHA.324
@TK2MSFTNGP10.phx.gbl:
Hi all,

I have a date field in a temp table as part of a DataSet. In some records the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....

If dtTemp("When") is system.dbnull.value then
Msgbox("oops dbnull!")
end if

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 21 '05 #4
When I try this I get an error msg that the row already belongs to the
table. I also to update the item by assigning the new value to
TableX.ItemArray(3)="new value"
One column is configured as PK auto.

"bblyth" <bb****@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
You Need to Edit the ItemArray associated with that row.

Also Rows.Add does work in a round about way

Dim DT As New Data.DataTable
Dim DR As Data.DataRow
DR = DT.NewRow
DR.ItemArray(0) = "Test"
DR.ItemArray(1) = "Test2"
DT.Rows.Add(DR)
"cjobes" wrote:
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value of another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the record is already there it would replace the data) and there isn't anything like "change" or "replace". How can I do this?

Thanks,

Claus
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"cjobes" <cj****@nova-tech.org> wrote in news:OAvLiZa1EHA.324
@TK2MSFTNGP10.phx.gbl:

> Hi all,
>
> I have a date field in a temp table as part of a DataSet. In some

records
> the value is DBNull. how can I trap the error with
> if dtTemp("When") = ??? Then.....
If dtTemp("When") is system.dbnull.value then
Msgbox("oops dbnull!")
end if

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 21 '05 #5
Claus,

Why would you add a row when you have to change an item in a column.
To give some explanation about items and columns.

A column is the description of a datatable column in such a column are items
Therefore
\\\
dim mycolumname as string = mytable.columns(0).columnname
///
gives you the name of the column
\\\
dim mycolumnitem as string = mytable.rows(0).item(0) or
dim mycolumnitem as string = mytable.rows(0).item(mycolumnname)
///
Gives you the first item in the first row

Therefore you need probably something as
\\\
mytable.rows(0).item(0) = myvalue
///
I hope this helps?

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:OZ**************@tk2msftngp13.phx.gbl...
Thanks, that worked.

Now that the project doesn't time out anymore, I found another problem.
Where the dtTemp("When") column is not DBNull I need to replace the value
of
another column (dtTemp("When2") with a value of a specific variable.
Rows.Add doesn't work (although the books say that if the PK value for the
record is already there it would replace the data) and there isn't
anything
like "change" or "replace". How can I do this?

Thanks,

Claus
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"cjobes" <cj****@nova-tech.org> wrote in news:OAvLiZa1EHA.324
@TK2MSFTNGP10.phx.gbl:
> Hi all,
>
> I have a date field in a temp table as part of a DataSet. In some records > the value is DBNull. how can I trap the error with
> if dtTemp("When") = ??? Then.....

If dtTemp("When") is system.dbnull.value then
Msgbox("oops dbnull!")
end if

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 21 '05 #6
Hi,

The datarow has an isnull method to tell if a field is dbnull.

http://msdn.microsoft.com/library/de...snulltopic.asp

Ken
-----------------------
"cjobes" <cj****@nova-tech.org> wrote in message
news:OA*************@TK2MSFTNGP10.phx.gbl...
Hi all,

I have a date field in a temp table as part of a DataSet. In some records
the value is DBNull. how can I trap the error with
if dtTemp("When") = ??? Then.....

Thanks,

Claus

Nov 21 '05 #7

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

Similar topics

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...
4
by: Tina | last post by:
I have instantiated an insertRow for a dataset. I now want to make the GLCode DBNull. I have tried: insertRow.GLCode = Convert.dbnull insertRow.GLCode = Convert.dbnull(insertRow.GLCode) and...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.