locked
Message="Conversion from type 'DBNull' to type 'Integer' is not valid." RRS feed

  • Question

  • User-1832071357 posted

    I have this code in Dardanelle.aspx page.

    12. Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)

    13. Dim pages As Integer

    14. pages = CInt(e.Command.Parameters("@pageCount").Value)

    15. Pn2.Count = pages

    16. End Sub

    The error below refers to line 14 above

    System.InvalidCastException was unhandled by user code

    Message="Conversion from type 'DBNull' to type 'Integer' is not valid."

    Source="Microsoft.VisualBasic"

    StackTrace:

    at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)

    at ASP.dardanelle_list_aspx.SqlDataSource1_Selected(Object sender, SqlDataSourceStatusEventArgs e) in C:\Documents and Settings\Owner\My Documents\Test Web site\Dardanelle\List.aspx:line 14

    at System.Web.UI.WebControls.SqlDataSourceView.OnSelected(SqlDataSourceStatusEventArgs e)

    at System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)

    at System.Web.UI.WebControls.Repeater.GetData()

    at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)

    at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)

    at System.Web.UI.WebControls.Repeater.DataBind()

    at System.Web.UI.WebControls.Repeater.EnsureDataBound()

    at System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e)

    at System.Web.UI.Control.PreRenderRecursiveInternal()

    at System.Web.UI.Control.PreRenderRecursiveInternal()

    at System.Web.UI.Control.PreRenderRecursiveInternal()

    at System.Web.UI.Control.PreRenderRecursiveInternal()

    at System.Web.UI.Control.PreRenderRecursiveInternal()

    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

     

    Any ideals on how to correct this?

    Monday, July 23, 2007 7:16 PM

Answers

  • User328432237 posted

    Hi

    I have no idea if this is going to help, but it will get rid of the error...

    Replace line 14 with this:

    If Not IsDBNull(e.Command.Parameters("@pageCount").Value) then
        pages = CInt(e.Command.Parameters("@pageCount").Value)
    Else
        pages = 0
    End IF

    This will stop the error from being a problem, but it looks like your problem is being caused by "e.Command.Parameters("@pageCount").Value" being a Null value and cannot be converted to an integer. You may have to check that you have data and that you are using the correct parameters of e.

    I hope this helps

    Quinton 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 24, 2007 1:59 AM
  • User-1832071357 posted

    Thank this worked. I can get to the page and everything working.

    Where would I check data for the correct parameters of e?

    lhr

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 24, 2007 4:21 PM

All replies

  • User328432237 posted

    Hi

    I have no idea if this is going to help, but it will get rid of the error...

    Replace line 14 with this:

    If Not IsDBNull(e.Command.Parameters("@pageCount").Value) then
        pages = CInt(e.Command.Parameters("@pageCount").Value)
    Else
        pages = 0
    End IF

    This will stop the error from being a problem, but it looks like your problem is being caused by "e.Command.Parameters("@pageCount").Value" being a Null value and cannot be converted to an integer. You may have to check that you have data and that you are using the correct parameters of e.

    I hope this helps

    Quinton 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 24, 2007 1:59 AM
  • User-1832071357 posted

    Thank this worked. I can get to the page and everything working.

    Where would I check data for the correct parameters of e?

    lhr

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 24, 2007 4:21 PM