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

Question: Best way to handle DBNULL in datareaders

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 withdatareaders.

Using the following syntax im getting errors when the field contains aDBNULL value
Textbox1.text = myreader(1)

My current solution for this is using the isnull function of MSSQL andsubstituting null's with "" there. This means a lot of typing for me, whichis never a good thing.

Does anyone have a better solution to my problem?
.

Nov 17 '05 #1
6 4306
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?
.

Nov 17 '05 #2
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" <no**@none.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
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?
.


Nov 17 '05 #3
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.
<Da**@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:#p**************@TK2MSFTNGP10.phx.gbl...
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" <no**@none.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
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?
>
>
>.
>



Nov 17 '05 #4
PJ
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" <no**@none.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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.
<Da**@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:#p**************@TK2MSFTNGP10.phx.gbl...
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" <no**@none.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
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?
> >
> >
> >.
> >



Nov 17 '05 #5

"PJ" <pj***@hotmail.com> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
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" <no**@none.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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.
<Da**@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:#p**************@TK2MSFTNGP10.phx.gbl...
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" <no**@none.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
> 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?
> > >
> > >
> > >.
> > >
>
>



Nov 17 '05 #6
thx :)

"PJ" <pj***@hotmail.com> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
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" <no**@none.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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.
<Da**@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
news:#p**************@TK2MSFTNGP10.phx.gbl...
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" <no**@none.com> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
> 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?
> > >
> > >
> > >.
> > >
>
>



Nov 17 '05 #7

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

Similar topics

5
by: PCL | last post by:
I am trying to get the value from a simple stored procedure - the Stored Procedure returns 1 record with one field - it is basically "Select Max(po) as MaxPo from PODB" I want to store that...
21
by: tshad | last post by:
I tried to do this: public static void GetValueFromDbObject(object dbObjectValue, ref decimal destination) { destination = dbObjectValue == DBNull.Value || "" ? decimal.MaxValue :...
5
by: Ryan Ternier | last post by:
I know how this should be done in regards to nTier, but it seems a bit inneficient, and was wondering if there's a solution that I havn't thought of yet. (I'm switching this loop to For Each Row...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
14
by: Steve | last post by:
Sorry in advance for my ignorance. Any help would sure be appreciated. I'm writing a fairly simple application with VB.Net and am obviously a bit of a newbie. This application will be used by 1,...
24
by: Karen Hill | last post by:
Suppose you have a textBox control. It is empty and you send the this.textBox1.Text.ToString() value into a database. The control does not send a NULL but instead a "". What is the _CORRECT_...
2
by: Maciek | last post by:
I've got this question regarding programming practices. I'm designing Newsletter module in my WebApp and I'm greenhorn in programming. There's a stored procedure which adds a subscriber to a DB. It...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.