Object can not be cast from DBNull to other types

1

I'm having a problem in the return "Object can not 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
    
asked by anonymous 19.03.2015 / 18:20

1 answer

-1

Inside 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 attempting to give a cast to Decimal, make a check before trying to cast a decimal.

    
19.03.2015 / 18:25