Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > allow NULLS

Reply
Thread Tools

allow NULLS

 
 
Mike
Guest
Posts: n/a
 
      06-19-2004
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.




 
Reply With Quote
 
 
 
 
Daniel Walzenbach
Guest
Posts: n/a
 
      06-19-2004
Mike,

try the following:

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

HTHs

Daniel Walzenbach


"Mike" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> 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.
>
>
>
>



 
Reply With Quote
 
 
 
 
M. Zeeshan Mustafa
Guest
Posts: n/a
 
      06-21-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>
>





 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      06-21-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >
> >
> >
> >

>
>
>
>



 
Reply With Quote
 
Daniel Walzenbach
Guest
Posts: n/a
 
      06-21-2004
Mike,

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

Greetings

Daniel

"Mike" <(E-Mail Removed)> schrieb im Newsbeitrag
news:enKN6A%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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.
> > >
> > >
> > >
> > >

> >
> >
> >
> >

>
>



 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      06-21-2004
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" <(E-Mail Removed)> wrote in
message news:OVscvF%(E-Mail Removed)...
> Mike,
>
> what exactly are you trying to do? Could you provide some more information
> plz?
>
> Greetings
>
> Daniel
>
> "Mike" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:enKN6A%(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in

message
> > news:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > 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.
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      06-21-2004
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" <(E-Mail Removed)> wrote in
message news:OVscvF%(E-Mail Removed)...
> Mike,
>
> what exactly are you trying to do? Could you provide some more information
> plz?
>
> Greetings
>
> Daniel
>
> "Mike" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:enKN6A%(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in

message
> > news:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > 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.
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >

> >
> >

>
>




 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      06-21-2004
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" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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.
>
>
>
>



 
Reply With Quote
 
[MSFT]
Guest
Posts: n/a
 
      06-22-2004
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie: allow deny vs deny allow Jeff ASP .Net 2 09-19-2006 02:12 AM
allow nulls in strongly typed data set asp.net =?Utf-8?B?U2NvdHRfZnJvbV9DYXJlbWF0aWM=?= ASP .Net 0 06-14-2006 06:56 PM
Location element in the Web.config file. Allow System Admin whole directory, allow others specific page Ryan Taylor ASP .Net Security 1 09-09-2004 06:52 PM
Inputting NULLS? Bill ASP .Net 1 12-11-2003 07:29 PM
Problem with nulls Bob ASP .Net 0 07-02-2003 07:11 PM



Advertisments