Chamuanza Posted April 4, 2025 at 04:01 PM Report #634601 Posted April 4, 2025 at 04:01 PM Boa Pessoal Estou com um erro numa aplicação pessoal na soma de Coluna em DataGrid O operador '+' não está definido para tipo 'Decimal' e tipo 'DBNull'. Junto código da rotina que estou a utilizar O Campo correspondente na BD Access está defenido como Moeda Agradeço desde já uma ajuda Private Sub SomaColuna() 'Somar a coluna de Despesa e Receita Dim SOMA As Decimal ' Dim Soma1 As Decimal 'Dim Corretor As Decimal For Each coluna As DataGridViewRow In MilleniumVáriosDataGridView.Rows SOMA = SOMA + coluna.Cells(5).Value 'Soma1 = Soma1 + coluna.Cells(3).Value Next Label3.Text = SOMA Label3.Text = Microsoft.VisualBasic.Format(Decimal.Parse(SOMA), "##,##0.00 €") End Sub
Solution Andrepereira9 Posted April 4, 2025 at 08:00 PM Solution Report #634605 Posted April 4, 2025 at 08:00 PM (edited) Boas Experimenta assim Private Sub SomaColuna() 'Somar a coluna de Despesa e Receita Dim SOMA As Decimal 'Dim Soma1 As Decimal 'Dim Corretor As Decimal For Each coluna As DataGridViewRow In MilleniumVáriosDataGridView.Rows 'Verifica se a célula não está vazia e não é uma linha nova If Not coluna.IsNewRow Then Dim valor = coluna.Cells(5).Value If Not IsDBNull(valor) AndAlso Not String.IsNullOrEmpty(valor.ToString()) Then SOMA += Convert.ToDecimal(valor) End If End If Next Label3.Text = Microsoft.VisualBasic.Format(Decimal.Parse(SOMA), "##,##0.00 €") End Sub Edited April 4, 2025 at 08:00 PM by Andrepereira9 A informática chegou para resolver problemas que antes não existiam Quem ri por último é porque está conectado a 52 Kbs.
Chamuanza Posted April 5, 2025 at 06:36 PM Author Report #634607 Posted April 5, 2025 at 06:36 PM Obrigado pela atenção e pela dica, funciona
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now