Type conversion going wrong

1

I'm having a data conversion problem when it passes For Each , it says that "vl_maodeobra" can not be converted from String to Integer type. The problem is that no matter the conversion I try to make the same error, just changing the message, for example: can not be converted from String to Double or Decimal.

The "vl_maodeobra" item returns numbers with commas, decimals, and Query below returns the data correctly. The error only appears when it passes the line vl_mo_total += mObra.Rows("vl_maodeobra").ToString() .

I'm trying to add the value of the workforce for each line that returns from the query .

SB = New System.Text.StringBuilder
SB.Append(" Select a.vl_maodeobra ")
SB.Append(" from garantia a ")
SB.Append(" where a.dt_exclusao is null ")
SB.Append(" and a.dt_inclusao >= to_date('01/01/2013', 'dd/mm/yyyy') ")
SB.Append(" and a.cd_laudo = 21 ")
SB.Append(" and cd_tipo_garantia <> 'C' ")
SB.Append(" and a.vl_total > 0 ")
SB.Append(" and a.nu_lote = " & LO.ToString & " ")
SB.Append(" and a.cd_concessionario = 5 ")
Dim mObra As DataTable = DB.CreateDataTable(SB.ToString)



If mObra.Rows.Count >= 1 Then
   Dim vl_mo_total As Double = 0
   For Each currow2 As DataRow In mObra.Rows
      vl_mo_total += mObra.Rows("vl_maodeobra").ToString()
   Next
    
asked by anonymous 06.04.2015 / 15:29

1 answer

1

Try this:

If mObra.Rows.Count >= 1 Then
   Dim vl_mo_total As Double = 0
   For Each currow2 As DataRow In mObra.Rows
      vl_mo_total += Convert.ToDouble(currow2("vl_maodeobra")) //esta é uma forma simplificada
   Next

It may need some adaptation in the conversion depending on what you need and how this data is returned.

But the question still remains, do you work with monetary value with type Double ? I hope it was just a test.

    
06.04.2015 / 15:36