473,394 Members | 1,701 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,394 software developers and data experts.

allow NULLS

The current databas structure that i'm working with allowed NULL's an now
I'm converting the app to .NET and it will not allow NULLs in the fields
when populated.
So my question is, how can i hande NULL's being pulled from the DB now?

When I try to access a page and if the field is NULL I get an error:

i do i fix this? I'm using VB.NET for coding

Cast from type 'DBNull' to type 'String' is not valid.


Nov 18 '05 #1
8 2307
Mike,

try the following:

if not isdbnull(yourvalue) then
' do sth
end if

HTHs

Daniel Walzenbach
"Mike" <me@me.com> schrieb im Newsbeitrag
news:Or**************@TK2MSFTNGP10.phx.gbl...
The current databas structure that i'm working with allowed NULL's an now
I'm converting the app to .NET and it will not allow NULLs in the fields
when populated.
So my question is, how can i hande NULL's being pulled from the DB now?

When I try to access a page and if the field is NULL I get an error:

i do i fix this? I'm using VB.NET for coding

Cast from type 'DBNull' to type 'String' is not valid.

Nov 18 '05 #2
Use iif turner operator available in visual basic, see reference below:
http://msdn.microsoft.com/library/en...l/vafctiif.asp

Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
TruePart:="",
FalsePart:=currentRow.Item(0))

So in above case if currentRow.Item(0) is dbnull, then it will return empty
string, otherwise
it will return currentRow.Item(0).

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Mike" <me@me.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
The current databas structure that i'm working with allowed NULL's an now
I'm converting the app to .NET and it will not allow NULLs in the fields
when populated.
So my question is, how can i hande NULL's being pulled from the DB now?

When I try to access a page and if the field is NULL I get an error:

i do i fix this? I'm using VB.NET for coding

Cast from type 'DBNull' to type 'String' is not valid.



Nov 18 '05 #3
thanks but im not populating a grid with empty values, I'm populating Text
boxes and some values are blank at times

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zeeshan.net> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Use iif turner operator available in visual basic, see reference below:
http://msdn.microsoft.com/library/en...l/vafctiif.asp

Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
TruePart:="",
FalsePart:=currentRow.Item(0))

So in above case if currentRow.Item(0) is dbnull, then it will return empty string, otherwise
it will return currentRow.Item(0).

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Mike" <me@me.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
The current databas structure that i'm working with allowed NULL's an now I'm converting the app to .NET and it will not allow NULLs in the fields
when populated.
So my question is, how can i hande NULL's being pulled from the DB now?

When I try to access a page and if the field is NULL I get an error:

i do i fix this? I'm using VB.NET for coding

Cast from type 'DBNull' to type 'String' is not valid.


Nov 18 '05 #4
Mike,

what exactly are you trying to do? Could you provide some more information
plz?

Greetings

Daniel

"Mike" <me@me.com> schrieb im Newsbeitrag
news:en****************@tk2msftngp13.phx.gbl...
thanks but im not populating a grid with empty values, I'm populating Text
boxes and some values are blank at times

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zeeshan.net> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Use iif turner operator available in visual basic, see reference below:
http://msdn.microsoft.com/library/en...l/vafctiif.asp

Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
TruePart:="",
FalsePart:=currentRow.Item(0))

So in above case if currentRow.Item(0) is dbnull, then it will return

empty
string, otherwise
it will return currentRow.Item(0).

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Mike" <me@me.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
The current databas structure that i'm working with allowed NULL's an now I'm converting the app to .NET and it will not allow NULLs in the fields when populated.
So my question is, how can i hande NULL's being pulled from the DB now?
When I try to access a page and if the field is NULL I get an error:

i do i fix this? I'm using VB.NET for coding

Cast from type 'DBNull' to type 'String' is not valid.



Nov 18 '05 #5
whats happening is that I have a main page (datagrid) and when a user
highlights a row and clicks the Edit button it takes them to a detailed edit
screen and some of the fields that are being pulled back from the database
have <NULL> in the fields instead of data (IE: Scooby) If the column has
<NULL> I'm getting an error
on the field name that has <NULL> in it but if the column is blank it works
fine.
I just need to get around <NULL> if it is in column instead of data

Cast from type 'DBNull' to type 'String' is not valid

"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:OV****************@TK2MSFTNGP11.phx.gbl...
Mike,

what exactly are you trying to do? Could you provide some more information
plz?

Greetings

Daniel

"Mike" <me@me.com> schrieb im Newsbeitrag
news:en****************@tk2msftngp13.phx.gbl...
thanks but im not populating a grid with empty values, I'm populating Text
boxes and some values are blank at times

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zeeshan.net> wrote in message news:OE**************@TK2MSFTNGP10.phx.gbl...
Use iif turner operator available in visual basic, see reference below: http://msdn.microsoft.com/library/en...l/vafctiif.asp

Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
TruePart:="",
FalsePart:=currentRow.Item(0))

So in above case if currentRow.Item(0) is dbnull, then it will return

empty
string, otherwise
it will return currentRow.Item(0).

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Mike" <me@me.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
> The current databas structure that i'm working with allowed NULL's
an now
> I'm converting the app to .NET and it will not allow NULLs in the

fields > when populated.
> So my question is, how can i hande NULL's being pulled from the DB now? >
> When I try to access a page and if the field is NULL I get an error:
>
> i do i fix this? I'm using VB.NET for coding
>
> Cast from type 'DBNull' to type 'String' is not valid.
>
>
>
>




Nov 18 '05 #6
whats happening is that I have a main page (datagrid) and when a user
highlights a row and clicks the Edit button it takes them to a detailed edit
screen and some of the fields that are being pulled back from the database
have <NULL> in the fields instead of data (IE: Scooby) If the column has
<NULL> I'm getting an error

"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:OV****************@TK2MSFTNGP11.phx.gbl...
Mike,

what exactly are you trying to do? Could you provide some more information
plz?

Greetings

Daniel

"Mike" <me@me.com> schrieb im Newsbeitrag
news:en****************@tk2msftngp13.phx.gbl...
thanks but im not populating a grid with empty values, I'm populating Text
boxes and some values are blank at times

"M. Zeeshan Mustafa" <ze*****@no-spm.please.zeeshan.net> wrote in message news:OE**************@TK2MSFTNGP10.phx.gbl...
Use iif turner operator available in visual basic, see reference below: http://msdn.microsoft.com/library/en...l/vafctiif.asp

Dim toReturn As String = IIf(Expression:=IsDBNull(currentRow.Item(0)),
TruePart:="",
FalsePart:=currentRow.Item(0))

So in above case if currentRow.Item(0) is dbnull, then it will return

empty
string, otherwise
it will return currentRow.Item(0).

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Mike" <me@me.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
> The current databas structure that i'm working with allowed NULL's
an now
> I'm converting the app to .NET and it will not allow NULLs in the

fields > when populated.
> So my question is, how can i hande NULL's being pulled from the DB now? >
> When I try to access a page and if the field is NULL I get an error:
>
> i do i fix this? I'm using VB.NET for coding
>
> Cast from type 'DBNull' to type 'String' is not valid.
>
>
>
>



Nov 18 '05 #7
Just create a function like this:

Public Function NullHelper(ByVal obj As Object) As String
If IsDBNull(obj) Then Return String.Empty
Return obj.ToString()
End Function

If check if the value is null and if it is, it will return a empty string.

"Mike" <me@me.com> schreef in bericht
news:Or**************@TK2MSFTNGP10.phx.gbl...
The current databas structure that i'm working with allowed NULL's an now
I'm converting the app to .NET and it will not allow NULLs in the fields
when populated.
So my question is, how can i hande NULL's being pulled from the DB now?

When I try to access a page and if the field is NULL I get an error:

i do i fix this? I'm using VB.NET for coding

Cast from type 'DBNull' to type 'String' is not valid.

Nov 18 '05 #8
Hi Mike,

Is the TextBox bound to a Dataset? If so, you may set the TextBox's
DataBings property. In Binding for Text, you can specify a custom binding
expression. For example, a function like Richard suggested.

Luke

Nov 18 '05 #9

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

Similar topics

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...
3
by: Trevor Best | last post by:
Is there a *simple* way to change a collumn from allowing null to not null? I just unchecked "allow nulls" in EM and the SQL it generates to do this one thing is astonishing, create table, drop...
5
by: Robert Stearns | last post by:
Either I missed something, or ALTER TABLE does not have this capability. Is there any way of doing it except DROPping all constraints which mention this table, EXPORTing the data, DROPping the...
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...
0
by: Steve Amey | last post by:
Hi all I am having a problem when I am updating my database. I am using a strong DS and the PK column is an Identity column, but when I am udating my database I am getting the exception 'Column...
0
by: Scott_from_Carematic | last post by:
I'm trying to use a strongly typed dataset in my asp.net (2.0) project with visual studio 2005. I have generated the dataset and tableadapters in the designer. I'm using SQL server EE 2005 as the...
3
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or...
5
by: John | last post by:
Hi I have a vb.net winform data app with sql server 2005 backend. The ID field in the tblClients table is an 'int' identity column that does not allow nulls. The problem is that when I try to...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
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...

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.