Question: Best way to handle DBNULL in datareaders

Discussion in 'ASP .Net' started by Ravikanth[MVP], Jul 17, 2003.

  1. 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?
    >
    >
    >.
    >
    Ravikanth[MVP], Jul 17, 2003
    #1
    1. Advertising

  2. Ravikanth[MVP]

    Aemca Guest

    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?
    > >
    > >
    > >.
    > >
    Aemca, Jul 17, 2003
    #2
    1. Advertising

  3. Ravikanth[MVP]

    Guest Guest

    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" <> wrote in message
    news:...
    > 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?
    > > >
    > > >
    > > >.
    > > >

    >
    >
    Guest, Jul 17, 2003
    #3
  4. Ravikanth[MVP]

    Aemca Guest

    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.


    <> wrote in message
    news:#...
    > 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" <> wrote in message
    > news:...
    > > 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?
    > > > >
    > > > >
    > > > >.
    > > > >

    > >
    > >

    >
    >
    Aemca, Jul 17, 2003
    #4
  5. Ravikanth[MVP]

    PJ Guest

    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" <> wrote in message
    news:...
    > 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.
    >
    >
    > <> wrote in message
    > news:#...
    > > 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" <> wrote in message
    > > news:...
    > > > 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?
    > > > > >
    > > > > >
    > > > > >.
    > > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    PJ, Jul 17, 2003
    #5
  6. Ravikanth[MVP]

    Aemca Guest

    "PJ" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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.
    > >
    > >
    > > <> wrote in message
    > > news:#...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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?
    > > > > > >
    > > > > > >
    > > > > > >.
    > > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Aemca, Jul 18, 2003
    #6
  7. Ravikanth[MVP]

    Aemca Guest

    thx :)

    "PJ" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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.
    > >
    > >
    > > <> wrote in message
    > > news:#...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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?
    > > > > > >
    > > > > > >
    > > > > > >.
    > > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Aemca, Jul 18, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guadala Harry

    ADO.NET DataReaders and the Middle Tier

    Guadala Harry, Feb 21, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    787
    Guadala Harry
    Feb 21, 2004
  2. Ryan Ternier
    Replies:
    5
    Views:
    1,243
    Kevin Spencer
    Nov 10, 2004
  3. Guest

    using datasets vs. datareaders

    Guest, Oct 22, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    482
    sloan
    Oct 23, 2007
  4. Mike Smith

    paging with datareaders

    Mike Smith, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    92
    Mike Smith
    Sep 22, 2003
  5. Replies:
    4
    Views:
    169
    Joe Smith
    May 4, 2007
Loading...

Share This Page