Error: String Conversion in Integer Type is Not Valid

Asked

Viewed 3,733 times

0

I have a Datagridview that loads all the data of a table, all the data are of type Short Text in BD. I call for an SQL statement to display in Datagridview, until this step goes all right, everything is loaded and displayed perfectly!

The problem is when I select a record (entire line), and ask to return this record to a form that has the respective fields so I can edit them, for the fields in the form type Textbox goes smoothly, but the error occurs when I try display the contents in a Combobox. This is when the error in attachment occurs, and such error cannot be solved.

Erro VB.Net 2015

In this Combobox, it is restricted to 2 items only, YES and NO. Without any type of editing, only selection of items from the list.

In the Module:

Public intCodigoFornecedor As Integer       ''TBL_Cadastrar_Fornecedores

No Form:
Private Sub PSelecionaFornecedor() ''Guarda o que foi selecionado  
            intCodigoFornecedor = CInt(dgvFornecedores.CurrentCell.Value.ToString())  
            Me.Dispose() ''Para esconder o Form  
    End Sub   

Private Sub PSelecionaFornecedor() ''Guarda o que foi selecionado  
        intCodigoFornecedor = CInt(CType(dgvFornecedores.CurrentRow().Cells("Codigo_Fornecedor").Value, String))  
        Me.Dispose() ''Para esconder o Form  
    End Sub

I’ve tried these two ways and I can’t fix it, someone knows?

1 answer

0


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

I advise you to make 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.

  • Right! Thank you very much! It worked!

  • For nothing. I could mark it as the right answer.

Browser other questions tagged

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