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.Te xt = "" & memberdata("COM PANY_ID")
Thanx! 8 1418
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("myCo lumn") ? String.Empty : dr["myColumn"];
and for int:
myInt = dr.IsNull("myCo lumn2") ? 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***@discussi ons.microsoft.c om> wrote in message
news:EF******** *************** ***********@mic rosoft.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.Te xt = "" & memberdata("COM PANY_ID")
Thanx!
"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message news:EF******** *************** ***********@mic rosoft.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.Te xt = "" & memberdata("COM PANY_ID")
Thanx!
If you use
txtcompanyid.Te xt = memberdata("COM PANY_ID").ToStr ing()
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
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***@discussi ons.microsoft.c om> wrote in message news:EF******** *************** ***********@mic rosoft.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.Te xt = "" & memberdata("COM PANY_ID")
Thanx!
If you use txtcompanyid.Te xt = memberdata("COM PANY_ID").ToStr ing() 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
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***@discussi ons.microsoft.c om> wrote in message news:EF******** *************** ***********@mic rosoft.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.Te xt = "" & memberdata("COM PANY_ID")
Thanx!
If you use txtcompanyid.Te xt = memberdata("COM PANY_ID").ToStr ing() 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
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***@discussi ons.microsoft.c om> wrote in message news:EF******** *************** ***********@mic rosoft.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.Te xt = "" & memberdata("COM PANY_ID")
Thanx!
If you use txtcompanyid.Te xt = memberdata("COM PANY_ID").ToStr ing() 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
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("myCo lumn") ? String.Empty : dr["myColumn"];
and for int:
myInt = dr.IsNull("myCo lumn2") ? 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***@discussi ons.microsoft.c om> wrote in message news:EF******** *************** ***********@mic rosoft.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.Te xt = "" & memberdata("COM PANY_ID")
Thanx!
"Chris" <Ch***@discussi ons.microsoft.c om> wrote in message news:9B******** *************** ***********@mic rosoft.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
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***@discussi ons.microsoft.c om> wrote in message news:9B******** *************** ***********@mic rosoft.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
The " & "" " on the right of each line should prevent nulls from being
|
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 them in the
columns anymore?
If so, how to go about removing the nulls with a script?
|
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 certain tasks have been completed.
A typical example would be a column say invoice_value
|
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
I'm no SQL expert, but if I'm summing (SUM) multiple fields and adding
them together in my SELECT how does SUM handle Null? In some situations a
single column in a single row is Null but and it's part of a larger GROUP BY
and SUM and from looking...
|
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, called Half, has a single integer input parameter and
divides this value by two to produce its result. It also tests the input
parameter to see if it is null; if it is null, it returns null. When I click
the Run button and try to use the SET TO...
| |
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 boat name in a text field OR a sail number in a text
field, and gets the desired boat record back (an exact match).
|
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 and so forth to the 1st string.
Any ideas how to go about this?
Thanks,
|
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 "absence" of data
is an entirely valid and useful value?
If the later is true, is there a better way to handle nulls that doing this
for each and every column of each and every table? I'm hoping there is
|
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 it--then hold the next value
through the next set of nulls, and so on.
See example below:
I wanna copy down batch "IMR138" in record ID 1, all the way to ID 10.
Then copy down batch "7138" all the way to ID 20 and so on....
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |