[thelist] Null Value from a database to a string?

Chris Johnston fuzzylizard at gmail.com
Wed Dec 29 14:30:20 CST 2004

On Wed, 29 Dec 2004 11:36:16 -0600, Casey Crookston
<casey at thecrookstons.com> wrote:
> asp.net in vb...
> I'm populating a form from a database row.  There's a column in the db for
> address and address2 incase the user needs a second line for their address.
> In the db address2 is allowed a null value, but when trying to populate the
> form I get this error:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Cast from type 'DBNull' to type 'String' is not valid.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.InvalidCastException: Cast from type 'DBNull' to
> type 'String' is not valid.
> Source Error:
> Line 95:   baddress2.text=mySingleMemberDtr("b_address2")
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On most databases, don't put anything in. If the field is blank, then
simply don't enter anything into that field/column in the database.
Let the DB worry about how to enter a null value.

chris johnston


"For millions of years, mankind lived just like the animals and
something happened which unleashed the power of our imagination, we
learned to talk."
Pink Floyd

More information about the thelist mailing list