Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Error with DBNull

Reply
Thread Tools

Error with DBNull

 
 
Filipe Cristóvão
Guest
Posts: n/a
 
      09-01-2004
Hi,
I know that this is a newbie's question, but I need to know how i do to know
if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.

--

Filipe Cristóvão


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      09-01-2004

"Filipe Cristóvão" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Hi,
> I know that this is a newbie's question, but I need to know how i do to know
> if a field in a table is DBNull.
> If I try to write (with response.write) the field, it gives me an error:
> "Cast from type 'DBNull' to type 'String' is not valid".
> Thanks for any help.
>
> --
>
> Filipe Cristóvão
>
>


Various options:
* You can test against DBNull.Value (if (myDataRow["field"] == DBNull.Value) ... )
* DataRow has an IsNull(..) method to check a specific column in that row
* Don't cast to string, but use the ToString() method, DBNull gives an empty string

Hans Kesting


 
Reply With Quote
 
 
 
 
Filipe Cristóvão
Guest
Posts: n/a
 
      09-01-2004
Tks for the help.
I relly needed to know it.

--

Filipe Cristóvão

"Hans Kesting" <(E-Mail Removed)> escreveu na mensagem
news:%23%(E-Mail Removed)...
>
> "Filipe Cristóvão" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...
> > Hi,
> > I know that this is a newbie's question, but I need to know how i do to

know
> > if a field in a table is DBNull.
> > If I try to write (with response.write) the field, it gives me an error:
> > "Cast from type 'DBNull' to type 'String' is not valid".
> > Thanks for any help.
> >
> > --
> >
> > Filipe Cristóvão
> >
> >

>
> Various options:
> * You can test against DBNull.Value (if (myDataRow["field"] ==

DBNull.Value) ... )
> * DataRow has an IsNull(..) method to check a specific column in that row
> * Don't cast to string, but use the ToString() method, DBNull gives an

empty string
>
> Hans Kesting
>
>



 
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
check for dbNull is throwing an error =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= ASP .Net 1 01-16-2006 08:30 PM
Strange DBNULL Error - Please Help! Martin ASP .Net 2 02-02-2004 09:23 AM
Cast from type 'DBNull' to type 'String' is not valid error Rob ASP .Net Datagrid Control 0 07-28-2003 09:11 PM
Question: Best way to handle DBNULL in datareaders Ravikanth[MVP] ASP .Net 6 07-18-2003 10:51 AM



Advertisments