Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Question: Best way to handle DBNULL in datareaders

Reply
Thread Tools

Question: Best way to handle DBNULL in datareaders

 
 
Ravikanth[MVP]
Guest
Posts: n/a
 
      07-17-2003
Hi

Alternative is check before assigning as TextBox value.

TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
(string)myRow["ColumnName"]

HTH
Ravikanth


>-----Original Message-----
>Im looking for the best way to handle DBNULL's in

datareaders.
>
>In a project im currently working on im using a lot of

optional data with
>datareaders.
>
>Using the following syntax im getting errors when the

field contains a
>DBNULL value
>Textbox1.text = myreader(1)
>
>My current solution for this is using the isnull

function of MSSQL and
>substituting null's with "" there. This means a lot of

typing for me, which
>is never a good thing.
>
>Does anyone have a better solution to my problem?
>
>
>.
>

 
Reply With Quote
 
 
 
 
Aemca
Guest
Posts: n/a
 
      07-17-2003
That was my first solution but thats way 2 much work to type that for each
value i want to use.

So this is not really a better solution for me.


> Hi
>
> Alternative is check before assigning as TextBox value.
>
> TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
> (string)myRow["ColumnName"]
>
> HTH
> Ravikanth
>
>
> >-----Original Message-----
> >Im looking for the best way to handle DBNULL's in

> datareaders.
> >
> >In a project im currently working on im using a lot of

> optional data with
> >datareaders.
> >
> >Using the following syntax im getting errors when the

> field contains a
> >DBNULL value
> >Textbox1.text = myreader(1)
> >
> >My current solution for this is using the isnull

> function of MSSQL and
> >substituting null's with "" there. This means a lot of

> typing for me, which
> >is never a good thing.
> >
> >Does anyone have a better solution to my problem?
> >
> >
> >.
> >



 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      07-17-2003
You could make a function which wraps the null and put that in...

Textbox1.text = CleanThis(myreader(1))

Have you tried adding the null to an empty string?

Textbox1.text = "" & myreader(1)

or something like that

It's not clear if you are using getstring or getvalue or what

....?

"Aemca" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> That was my first solution but thats way 2 much work to type that for each
> value i want to use.
>
> So this is not really a better solution for me.
>
>
> > Hi
> >
> > Alternative is check before assigning as TextBox value.
> >
> > TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
> > (string)myRow["ColumnName"]
> >
> > HTH
> > Ravikanth
> >
> >
> > >-----Original Message-----
> > >Im looking for the best way to handle DBNULL's in

> > datareaders.
> > >
> > >In a project im currently working on im using a lot of

> > optional data with
> > >datareaders.
> > >
> > >Using the following syntax im getting errors when the

> > field contains a
> > >DBNULL value
> > >Textbox1.text = myreader(1)
> > >
> > >My current solution for this is using the isnull

> > function of MSSQL and
> > >substituting null's with "" there. This means a lot of

> > typing for me, which
> > >is never a good thing.
> > >
> > >Does anyone have a better solution to my problem?
> > >
> > >
> > >.
> > >

>
>



 
Reply With Quote
 
Aemca
Guest
Posts: n/a
 
      07-17-2003
any suggestions on how to implement this ?
aka what should be in there

and this is the way that it is implemented, the .getvalue / getstring are
omitted.


<(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> You could make a function which wraps the null and put that in...
>
> Textbox1.text = CleanThis(myreader(1))
>
> Have you tried adding the null to an empty string?
>
> Textbox1.text = "" & myreader(1)
>
> or something like that
>
> It's not clear if you are using getstring or getvalue or what
>
> ...?
>
> "Aemca" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > That was my first solution but thats way 2 much work to type that for

each
> > value i want to use.
> >
> > So this is not really a better solution for me.
> >
> >
> > > Hi
> > >
> > > Alternative is check before assigning as TextBox value.
> > >
> > > TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
> > > (string)myRow["ColumnName"]
> > >
> > > HTH
> > > Ravikanth
> > >
> > >
> > > >-----Original Message-----
> > > >Im looking for the best way to handle DBNULL's in
> > > datareaders.
> > > >
> > > >In a project im currently working on im using a lot of
> > > optional data with
> > > >datareaders.
> > > >
> > > >Using the following syntax im getting errors when the
> > > field contains a
> > > >DBNULL value
> > > >Textbox1.text = myreader(1)
> > > >
> > > >My current solution for this is using the isnull
> > > function of MSSQL and
> > > >substituting null's with "" there. This means a lot of
> > > typing for me, which
> > > >is never a good thing.
> > > >
> > > >Does anyone have a better solution to my problem?
> > > >
> > > >
> > > >.
> > > >

> >
> >

>
>



 
Reply With Quote
 
PJ
Guest
Posts: n/a
 
      07-17-2003
You can simply use .ToString() on varchar fields.

dr(0).ToString()

That will return an empty string if it's a null varchar field.

"Aemca" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> any suggestions on how to implement this ?
> aka what should be in there
>
> and this is the way that it is implemented, the .getvalue / getstring are
> omitted.
>
>
> <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
> > You could make a function which wraps the null and put that in...
> >
> > Textbox1.text = CleanThis(myreader(1))
> >
> > Have you tried adding the null to an empty string?
> >
> > Textbox1.text = "" & myreader(1)
> >
> > or something like that
> >
> > It's not clear if you are using getstring or getvalue or what
> >
> > ...?
> >
> > "Aemca" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > That was my first solution but thats way 2 much work to type that for

> each
> > > value i want to use.
> > >
> > > So this is not really a better solution for me.
> > >
> > >
> > > > Hi
> > > >
> > > > Alternative is check before assigning as TextBox value.
> > > >
> > > > TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
> > > > (string)myRow["ColumnName"]
> > > >
> > > > HTH
> > > > Ravikanth
> > > >
> > > >
> > > > >-----Original Message-----
> > > > >Im looking for the best way to handle DBNULL's in
> > > > datareaders.
> > > > >
> > > > >In a project im currently working on im using a lot of
> > > > optional data with
> > > > >datareaders.
> > > > >
> > > > >Using the following syntax im getting errors when the
> > > > field contains a
> > > > >DBNULL value
> > > > >Textbox1.text = myreader(1)
> > > > >
> > > > >My current solution for this is using the isnull
> > > > function of MSSQL and
> > > > >substituting null's with "" there. This means a lot of
> > > > typing for me, which
> > > > >is never a good thing.
> > > > >
> > > > >Does anyone have a better solution to my problem?
> > > > >
> > > > >
> > > > >.
> > > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Aemca
Guest
Posts: n/a
 
      07-18-2003

"PJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You can simply use .ToString() on varchar fields.
>
> dr(0).ToString()
>
> That will return an empty string if it's a null varchar field.
>
> "Aemca" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > any suggestions on how to implement this ?
> > aka what should be in there
> >
> > and this is the way that it is implemented, the .getvalue / getstring

are
> > omitted.
> >
> >
> > <(E-Mail Removed)> wrote in message
> > news:#(E-Mail Removed)...
> > > You could make a function which wraps the null and put that in...
> > >
> > > Textbox1.text = CleanThis(myreader(1))
> > >
> > > Have you tried adding the null to an empty string?
> > >
> > > Textbox1.text = "" & myreader(1)
> > >
> > > or something like that
> > >
> > > It's not clear if you are using getstring or getvalue or what
> > >
> > > ...?
> > >
> > > "Aemca" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > That was my first solution but thats way 2 much work to type that

for
> > each
> > > > value i want to use.
> > > >
> > > > So this is not really a better solution for me.
> > > >
> > > >
> > > > > Hi
> > > > >
> > > > > Alternative is check before assigning as TextBox value.
> > > > >
> > > > > TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
> > > > > (string)myRow["ColumnName"]
> > > > >
> > > > > HTH
> > > > > Ravikanth
> > > > >
> > > > >
> > > > > >-----Original Message-----
> > > > > >Im looking for the best way to handle DBNULL's in
> > > > > datareaders.
> > > > > >
> > > > > >In a project im currently working on im using a lot of
> > > > > optional data with
> > > > > >datareaders.
> > > > > >
> > > > > >Using the following syntax im getting errors when the
> > > > > field contains a
> > > > > >DBNULL value
> > > > > >Textbox1.text = myreader(1)
> > > > > >
> > > > > >My current solution for this is using the isnull
> > > > > function of MSSQL and
> > > > > >substituting null's with "" there. This means a lot of
> > > > > typing for me, which
> > > > > >is never a good thing.
> > > > > >
> > > > > >Does anyone have a better solution to my problem?
> > > > > >
> > > > > >
> > > > > >.
> > > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Aemca
Guest
Posts: n/a
 
      07-18-2003
thx

"PJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You can simply use .ToString() on varchar fields.
>
> dr(0).ToString()
>
> That will return an empty string if it's a null varchar field.
>
> "Aemca" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > any suggestions on how to implement this ?
> > aka what should be in there
> >
> > and this is the way that it is implemented, the .getvalue / getstring

are
> > omitted.
> >
> >
> > <(E-Mail Removed)> wrote in message
> > news:#(E-Mail Removed)...
> > > You could make a function which wraps the null and put that in...
> > >
> > > Textbox1.text = CleanThis(myreader(1))
> > >
> > > Have you tried adding the null to an empty string?
> > >
> > > Textbox1.text = "" & myreader(1)
> > >
> > > or something like that
> > >
> > > It's not clear if you are using getstring or getvalue or what
> > >
> > > ...?
> > >
> > > "Aemca" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > That was my first solution but thats way 2 much work to type that

for
> > each
> > > > value i want to use.
> > > >
> > > > So this is not really a better solution for me.
> > > >
> > > >
> > > > > Hi
> > > > >
> > > > > Alternative is check before assigning as TextBox value.
> > > > >
> > > > > TextBox1.Text =myRow["ColumnName"]==DBNull.Value)?"":
> > > > > (string)myRow["ColumnName"]
> > > > >
> > > > > HTH
> > > > > Ravikanth
> > > > >
> > > > >
> > > > > >-----Original Message-----
> > > > > >Im looking for the best way to handle DBNULL's in
> > > > > datareaders.
> > > > > >
> > > > > >In a project im currently working on im using a lot of
> > > > > optional data with
> > > > > >datareaders.
> > > > > >
> > > > > >Using the following syntax im getting errors when the
> > > > > field contains a
> > > > > >DBNULL value
> > > > > >Textbox1.text = myreader(1)
> > > > > >
> > > > > >My current solution for this is using the isnull
> > > > > function of MSSQL and
> > > > > >substituting null's with "" there. This means a lot of
> > > > > typing for me, which
> > > > > >is never a good thing.
> > > > > >
> > > > > >Does anyone have a better solution to my problem?
> > > > > >
> > > > > >
> > > > > >.
> > > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
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
using datasets vs. datareaders ASP .Net 2 10-23-2007 01:27 PM
nTier question regarding DataSets and DataReaders Ryan Ternier ASP .Net 5 11-10-2004 09:48 PM
Best way to handle documents in ASP.NET Thomas Scheiderich ASP .Net 11 05-20-2004 05:57 PM
ADO.NET DataReaders and the Middle Tier Guadala Harry ASP .Net 7 02-21-2004 10:32 PM
paging with datareaders Mike Smith ASP .Net Datagrid Control 0 09-22-2003 07:01 PM



Advertisments