locked
Conversion from type 'DBNull' to type 'String' is not valid RRS feed

  • Question

  • User75903138 posted

    I'm getting a error message saying:

    Server Error in '/' Application.

    Conversion 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: Conversion from type 'DBNull' to type 'String' is not valid.

    Source Error:

    Line 113:                            </h3>
    Line 114:                            <p>
    Line 115:                                <asp:Label ID="descriptionLabel" runat="server" Text='<%# truncate(CStr(Eval("description"))) %>' />
    Line 116:                                <a href='<%# "Events_view.aspx?Eventid=" &Cstr( Eval("ID"))%>'>read more &raquo;</a></p>
    Line 117:                            <div class="clearlist">


    Source File: d:\hosting\thanhmofo\Events_List.aspx    Line: 115

     Do you guys know how fix this? I never had this problem before until last week. The website has been up for a little over a year without any problems.

    Monday, January 14, 2008 10:41 AM

All replies

  • User-125547262 posted

    You need to check if the value returned is null. If you have a stored proc or in the sql do the following

    isnull(description,'') as description.

    This would change the null values to an empty string 

    Monday, January 14, 2008 11:12 AM
  • User75903138 posted

    I got my problem fixed, it has something to do with the SQL database under the event table. I just re-created the event table and it works fine.

    Tuesday, January 15, 2008 6:19 PM
  • User-319574463 posted

    In TSQL, instead of

    SELECT A, isnull(description,'') as description, .....

    use SELECT A, COALESCE(description, '') AS  description, ....

    Tuesday, January 15, 2008 6:24 PM