473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

quick fix nulls

I know the reason why I get an error when the fields are set to null, but I'm working with old data that contains them. Any quick fixes? was hoping to avoid writing out every field in sql statement for ISNULL and avoid the long check on the make equal to value. Ideas?

Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!

Nov 18 '05 #1
8 1398
How are you retrieving the data? Are you using a DataSet, a reader? or
other means?

Maybe it doesn't matter much because you're really just stuck with using
some conditional checking. A common method I use for strings is, assuming
dr is a DataRow from my DataSet.Table

myString = dr.IsNull("myColumn") ? String.Empty : dr["myColumn"];

and for int:

myInt = dr.IsNull("myColumn2") ? 0 : dr["myColumn2"];

There are a lot of reasons for using nulls in data. It's not just a
leftover condition of "old data". For instance, dates that haven't been
assigned. You don't want to have to compare every date against January 1,
1753.

It's best to test for null on every field that allows nulls because someone
somewhere and somehow will get a null in even if you try to code them out.

Hope this helps,

Dale Preston
MCAD, MCSE, MCDBA
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
I know the reason why I get an error when the fields are set to null, but I'm working with old data that contains them. Any quick fixes? was hoping to
avoid writing out every field in sql statement for ISNULL and avoid the long
check on the make equal to value. Ideas?
Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!

Nov 18 '05 #2

"Chris" <Ch***@discussions.microsoft.com> wrote in message news:EF**********************************@microsof t.com...
I know the reason why I get an error when the fields are set to null, but I'm working with old data that contains them. Any quick fixes? was hoping to avoid writing out every field in sql statement for ISNULL and avoid the long check on the make equal to value.
Ideas?
Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!


If you use
txtcompanyid.Text = memberdata("COMPANY_ID").ToString()
you should have less 'problems' with a DbNull value: a "ToString()" of DbNull
(or DbNull.Value to be exact) gives an empty string.

If the value is "null" ("Nothing" in vb) this will not work, but a database "null"
is signalled by DbNull.Value.

Hans Kesting


Nov 18 '05 #3
I've tried your suggestion but stil get:
Error in: http://....../default.aspx
Error Message: Cast from type 'DBNull' to type 'String' is not valid.

Any thoughts?

"Hans Kesting" wrote:

"Chris" <Ch***@discussions.microsoft.com> wrote in message news:EF**********************************@microsof t.com...
I know the reason why I get an error when the fields are set to null, but I'm working with old data that contains them. Any quick

fixes? was hoping to avoid writing out every field in sql statement for ISNULL and avoid the long check on the make equal to value.
Ideas?

Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!


If you use
txtcompanyid.Text = memberdata("COMPANY_ID").ToString()
you should have less 'problems' with a DbNull value: a "ToString()" of DbNull
(or DbNull.Value to be exact) gives an empty string.

If the value is "null" ("Nothing" in vb) this will not work, but a database "null"
is signalled by DbNull.Value.

Hans Kesting


Nov 18 '05 #4
I tried your suugestions but I still get:

Error in: http://....../default.aspx
Error Message: Cast from type 'DBNull' to type 'String' is not valid.

Any thoughts?
"Hans Kesting" wrote:

"Chris" <Ch***@discussions.microsoft.com> wrote in message news:EF**********************************@microsof t.com...
I know the reason why I get an error when the fields are set to null, but I'm working with old data that contains them. Any quick

fixes? was hoping to avoid writing out every field in sql statement for ISNULL and avoid the long check on the make equal to value.
Ideas?

Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!


If you use
txtcompanyid.Text = memberdata("COMPANY_ID").ToString()
you should have less 'problems' with a DbNull value: a "ToString()" of DbNull
(or DbNull.Value to be exact) gives an empty string.

If the value is "null" ("Nothing" in vb) this will not work, but a database "null"
is signalled by DbNull.Value.

Hans Kesting


Nov 18 '05 #5
I tried your suugestions but I still get:

Error in: http://....../default.aspx
Error Message: Cast from type 'DBNull' to type 'String' is not valid.

Any thoughts?
"Hans Kesting" wrote:

"Chris" <Ch***@discussions.microsoft.com> wrote in message news:EF**********************************@microsof t.com...
I know the reason why I get an error when the fields are set to null, but I'm working with old data that contains them. Any quick

fixes? was hoping to avoid writing out every field in sql statement for ISNULL and avoid the long check on the make equal to value.
Ideas?

Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!


If you use
txtcompanyid.Text = memberdata("COMPANY_ID").ToString()
you should have less 'problems' with a DbNull value: a "ToString()" of DbNull
(or DbNull.Value to be exact) gives an empty string.

If the value is "null" ("Nothing" in vb) this will not work, but a database "null"
is signalled by DbNull.Value.

Hans Kesting


Nov 18 '05 #6
Do you know the VB equivelant?

"Dale" wrote:
How are you retrieving the data? Are you using a DataSet, a reader? or
other means?

Maybe it doesn't matter much because you're really just stuck with using
some conditional checking. A common method I use for strings is, assuming
dr is a DataRow from my DataSet.Table

myString = dr.IsNull("myColumn") ? String.Empty : dr["myColumn"];

and for int:

myInt = dr.IsNull("myColumn2") ? 0 : dr["myColumn2"];

There are a lot of reasons for using nulls in data. It's not just a
leftover condition of "old data". For instance, dates that haven't been
assigned. You don't want to have to compare every date against January 1,
1753.

It's best to test for null on every field that allows nulls because someone
somewhere and somehow will get a null in even if you try to code them out.

Hope this helps,

Dale Preston
MCAD, MCSE, MCDBA
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
I know the reason why I get an error when the fields are set to null, but

I'm working with old data that contains them. Any quick fixes? was hoping to
avoid writing out every field in sql statement for ISNULL and avoid the long
check on the make equal to value. Ideas?

Sql statement (I know I could use parameter):
"SELECT * FROM COMPANY_INFO WHERE COMPANY_ID = '" & usercompanyid & "'"
Setting value example:
txtcompanyid.Text = "" & memberdata("COMPANY_ID")

Thanx!


Nov 18 '05 #7

"Chris" <Ch***@discussions.microsoft.com> wrote in message news:9B**********************************@microsof t.com...
I've tried your suggestion but stil get:
Error in: http://....../default.aspx
Error Message: Cast from type 'DBNull' to type 'String' is not valid.

Any thoughts?

"Hans Kesting" wrote:


What code did you use?
The ToString method does no "casting", so that shouldn't cause this error.

Vb.net might handle things a bit different from C#. I don't know, I use
only C#, so I can't help you much there.

Hans Kesting
Nov 18 '05 #8
thanx. I only know VB at the moment. I ended up going to the data and replacing the Null values with either data or blanks. This fixed the issue in the temp. The data moving forward uses a different set of validation and is more stable. But I'd like to work on this since I'm sure it will come back up again.

Thanx.

"Hans Kesting" wrote:

"Chris" <Ch***@discussions.microsoft.com> wrote in message news:9B**********************************@microsof t.com...
I've tried your suggestion but stil get:
Error in: http://....../default.aspx
Error Message: Cast from type 'DBNull' to type 'String' is not valid.

Any thoughts?

"Hans Kesting" wrote:


What code did you use?
The ToString method does no "casting", so that shouldn't cause this error.

Vb.net might handle things a bit different from C#. I don't know, I use
only C#, so I can't help you much there.

Hans Kesting

Nov 18 '05 #9

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

Similar topics

0
by: Dan Perlman | last post by:
From: "Dan Perlman" <dan@dpci.NOSPAM.us> Subject: ODBC creating nulls? Date: Friday, July 09, 2004 10:43 AM Hi, Below is my VB6 code that writes data from an Access 2000 table to a PG table....
2
by: Steve Walker | last post by:
Hi all. I've been tasked with "speeding up" a mid-sized production system. It is riddled with nulls... "IsNull" all over the procs, etc. Is it worth it to get rid of the nulls and not allow...
3
by: aaj | last post by:
Hi I am probably going to regret asking this because I'm sure you are going to tell me my design is bad 8-) ah well we all have to learn.... anyway I often use Nulls as a marker to see if...
6
by: mike | last post by:
I'm doing what I thought was a simple GROUP BY summary of fairly simple data and the my numbers aren't working out Some results are showing up <NULL> when I know the data is in the database ...
0
by: Rhino | last post by:
I am working with SQL Functions in DB2 for Windows/Linux/UNIX (V8.2.1) and am having a problem setting input parameters for SQL Functions to null in the Development Center. My simple function,...
1
by: PST | last post by:
Here's a problem I'm trying to deal with: I'm working on a Frontpage 2000 website for a boat handicapping system, built in Access 97. What I'm trying to accomplish is: The user enters a...
13
by: jt | last post by:
I can't seem to find a way to concatenate strings that have nulls within the string. I have a string that I need another string that has nulls in it and what to append the 2nd string, 3 string...
3
by: Simon | last post by:
Hi all, Do you think the best way to avoid the problems of nulls in the database is just to provide default values via the db schema? Alternatively, is it better to allow nulls, seeing as the...
6
by: Cliff72 | last post by:
I need to fill in the nulls in the batch field the value from the record immediately preceding the null one ie replace the nulls with the preceding value until I hit a record with a value in...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.