Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Cast from type 'DBNull' to type 'String' is not valid.


Message #1 by "Sam Huang" <sttian@y...> on Sun, 9 Mar 2003 15:50:41
Thank you for your kind reply!!!

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 71:         End If
Line 72:         statusTextBox.Text = orderReader("Description")
Line 73:         If Not orderReader("AuthCode").GetType() Is GetType
(DBNull) Then
Line 74:             authCodeTextBox.Text = orderReader("AuthCode")
Line 75:             referenceTextBox.Text = orderReader("Reference")
 

Source File: C:\BegECom\Chapter13
\WroxJokeShop\UserControls\OrderDetailsAdmin.ascx.vb    Line: 73 
Message #2 by "Sam Huang" <sttian@y...> on Wed, 12 Mar 2003 00:27:34
Try change the Database table field definition.
> Thank you for your kind reply!!!

> Cast from type 'DBNull' to type 'String' is not valid. 
D> escription: An unhandled exception occurred during the execution of the 
c> urrent web request. Please review the stack trace for more information 
a> bout the error and where it originated in the code. 

> Exception Details: System.InvalidCastException: Cast from type 'DBNull' 
to 
t> ype 'String' is not valid.

> Source Error: 

> 
L> ine 71:         End If
L> ine 72:         statusTextBox.Text = orderReader("Description")
L> ine 73:         If Not orderReader("AuthCode").GetType() Is GetType
(> DBNull) Then
L> ine 74:             authCodeTextBox.Text = orderReader("AuthCode")
L> ine 75:             referenceTextBox.Text = orderReader("Reference")
 > 

> Source File: C:\BegECom\Chapter13
\> WroxJokeShop\UserControls\OrderDetailsAdmin.ascx.vb    Line: 73 
Message #3 by "Jerry Lanphear" <jerrylan@q...> on Tue, 11 Mar 2003 17:40:16 -0700
The only thing you have to change is as follows:

Change:
statusTextBox.Text = orderReader("Description")
To:
statusTextBox.Text = orderReader("Description") & ""

And do that for all possible fields containing null strings.  Forget all
the if/null statements. They are unnecessary.

This automatically performs the cast correctly regardless of null value
Regards
-----Original Message-----
From: Sam Huang [mailto:sttian@y...] 
Sent: Wednesday, March 12, 2003 12:28 AM
To: aspx_beginners
Subject: [aspx_beginners] Re: Cast from type 'DBNull' to type 'String'
is not valid.

Try change the Database table field definition.
> Thank you for your kind reply!!!

> Cast from type 'DBNull' to type 'String' is not valid. 
D> escription: An unhandled exception occurred during the execution of
the 
c> urrent web request. Please review the stack trace for more
information 
a> bout the error and where it originated in the code. 

> Exception Details: System.InvalidCastException: Cast from type
'DBNull' 
to 
t> ype 'String' is not valid.

> Source Error: 

> 
L> ine 71:         End If
L> ine 72:         statusTextBox.Text = orderReader("Description")
L> ine 73:         If Not orderReader("AuthCode").GetType() Is GetType
(> DBNull) Then
L> ine 74:             authCodeTextBox.Text = orderReader("AuthCode")
L> ine 75:             referenceTextBox.Text = orderReader("Reference")
 > 

> Source File: C:\BegECom\Chapter13
\> WroxJokeShop\UserControls\OrderDetailsAdmin.ascx.vb    Line: 73 




  Return to Index