Question: Best way to handle DBNULL in datareaders

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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 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] Guest

  2. Similar Questions and Discussions

    1. DBNull problems - typed datasets - webservices
      I'm using a typed dataset to get rows from a database, but getting an invalid cast exception when trying to examine columns in that row which are...
    2. paging with datareaders
      Hey people, When a datareader is used for paging with a datagrid in asp.net, we have to use the custom paging method ? How do we find out the...
    3. How to check if CType(e.Item.DataItem, DataRowView) is DBNULL
      How do you check if CType(e.Item.DataItem, DataRowView) is DBNULL? I have a Datagrid with Edit,Update, and Insert buttons to a SQL data table. ...
    4. Cast from type 'DBNull' to type 'String' is not valid error
      Trying to add an insert button Sub btnAddRow_Click event for adding a row to the datagrid and dataset back to SQL. Had it working per the...
    5. Question: Handle Events From Web User Controls
      I was reading an article that talked about using the OnBubbleEvent overrides function to handle events from a web user control...
  3. #2

    Default Re: Question: Best way to handle DBNULL in datareaders

    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 Guest

  4. #3

    Default Re: Question: Best way to handle DBNULL in datareaders

    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" <none@none.com> wrote in message
    news:eCQJpFGTDHA.2852@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?
    > > >
    > > >
    > > >.
    > > >
    >
    >

    Guest

  5. #4

    Default Re: Question: Best way to handle DBNULL in datareaders

    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.


    <DanR@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
    news:#pz2GmGTDHA.2148@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" <none@none.com> wrote in message
    > news:eCQJpFGTDHA.2852@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?
    > > > >
    > > > >
    > > > >.
    > > > >
    > >
    > >
    >
    >

    Aemca Guest

  6. #5

    Default Re: Question: Best way to handle DBNULL in datareaders

    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" <none@none.com> wrote in message
    news:urhX2zGTDHA.2084@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.
    >
    >
    > <DanR@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
    > news:#pz2GmGTDHA.2148@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" <none@none.com> wrote in message
    > > news:eCQJpFGTDHA.2852@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?
    > > > > >
    > > > > >
    > > > > >.
    > > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    PJ Guest

  7. #6

    Default Re: Question: Best way to handle DBNULL in datareaders


    "PJ" <pjwal@hotmail.com> wrote in message
    news:ODfDfQITDHA.2180@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" <none@none.com> wrote in message
    > news:urhX2zGTDHA.2084@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.
    > >
    > >
    > > <DanR@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
    > > news:#pz2GmGTDHA.2148@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" <none@none.com> wrote in message
    > > > news:eCQJpFGTDHA.2852@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?
    > > > > > >
    > > > > > >
    > > > > > >.
    > > > > > >
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Aemca Guest

  8. #7

    Default Re: Question: Best way to handle DBNULL in datareaders

    thx :)

    "PJ" <pjwal@hotmail.com> wrote in message
    news:ODfDfQITDHA.2180@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" <none@none.com> wrote in message
    > news:urhX2zGTDHA.2084@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.
    > >
    > >
    > > <DanR@REMOVETHISTOGETTOME-warshawgroup.com> wrote in message
    > > news:#pz2GmGTDHA.2148@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" <none@none.com> wrote in message
    > > > news:eCQJpFGTDHA.2852@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?
    > > > > > >
    > > > > > >
    > > > > > >.
    > > > > > >
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Aemca Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139