Object cannot be cast from Dbnull to other types

Asked

Viewed 137 times

1

I’m having a problem with Return "Object cannot be cast from Dbnull to other types", how to proceed?

        Public Function RetornaValorTotalPremiacao(ByVal strCodigoProposta As String) As Decimal
        Try
            Dim objApoioConexao As New ApoioConexao

            objApoioConexao.AdicionaParametro(strCodigoProposta, "@CD_PROP")

            Return Convert.ToDecimal(objDMConexao.ExecutaComando(My.Settings.ConexaoAtiva, "[dbo].[usp_sel_valor_total_premiacao]", CommandType.StoredProcedure, objApoioConexao.RetornaArrayParametros))

        Catch ex As Exception
            Throw
        End Try
    End Function

1 answer

-1

Within the code

bjDMConexao.ExecutaComando(My.Settings.ConexaoAtiva, "[dbo].[usp_sel_valor_total_premiacao]", CommandType.StoredProcedure, objApoioConexao.RetornaArrayParametros)

The value returned is Dbnull, and you are trying to give a cast to Decimal, do a check before trying to give a cast to decimal.

  • Solved ISNULL(SUM(PRO.VALOR_CUSTA),0)!

  • Poses as answer to help next humans with the same problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.