Error: String Conversion in Type 'Integer' is not Valid

0

I have a DataGridView that loads all the data from a table, all data is of Short Text type in the DB. I make the call by a SQL statement to display in the DataGridView, until that step goes well, everything is loaded and displayed perfectly!

The problem is when I select a record (whole line), and I ask to return this record to a form that has the respective fields so that I can edit them, so the fields in the form of type TextBox will quiet, but the error occurs when I try display the contents in a ComboBox. It is at this time that it gives the attached error, and such an error I can not solve.

InthisCombobox,only2itemsarerestricted,YESandNO.Withoutanysortofediting,justselecttheitemsfromthelist.

InModule:

PublicintCodigoFornecedorAsInteger''TBL_Cadastrar_FornecedoresNoForm:PrivateSubPSelecionaFornecedor()''GuardaoquefoiselecionadointCodigoFornecedor=CInt(dgvFornecedores.CurrentCell.Value.ToString())Me.Dispose()''ParaesconderoFormEndSubPrivateSubPSelecionaFornecedor()''GuardaoquefoiselecionadointCodigoFornecedor=CInt(CType(dgvFornecedores.CurrentRow().Cells("Codigo_Fornecedor").Value, String))  
        Me.Dispose() ''Para esconder o Form  
    End Sub

I have tried these two ways and I can not solve it, does anyone know?

    
asked by anonymous 29.04.2017 / 02:44

1 answer

0

The error happens because you are trying to convert the word "YES" to int.

I advise you to do an if:

if dgvFornecedores.CurrentRow().Cells("Codigo_Fornecedor").Value = "SIM" then intCodigoFornecedor = 1 else intCodigoFornecedor = 0 end if

Dai just use the logic you need.

    
19.05.2017 / 14:11