none
INSERT com Erro: Tipo de dados imcompatível na expressão de critério. RRS feed

  • Pergunta

  • Alguém tem alguma dica?

    Fazendo o BreakPoint o Erro aparece na linha:  Catch ex As System.Data.OleDb.OleDbException

    A descrição dos campos estão corretas, assim com a sua ordem.

    O código INSERT no Access abaixo:

     Private Sub inserir()
            Dim conecte As New OleDbConnection
            conecte.ConnectionString = My.Settings.SIConecte
            Try
                conecte.Open()
            Catch ex As System.Data.OleDb.OleDbException
                Label1.Text = "Erro de conexao com o Banco de Dados: " & ex.Message.ToString
                Return
            End Try
            Dim selcom As New System.Data.OleDb.OleDbCommand
            selcom.Connection = conecte
            selcom.CommandText = "INSERT INTO tbVETAARH (codSINA,codSexoPac,dataNascPac,UFCODPac,MUNCODPac,bairroPac,codVetOcupa,codTipoExp,codLocal,codFerimento,codTipoFerim,dataExp,observaPac,nomePropr,sobrenomeProp,codSexoProp,dataNascimProp,CodSituacaoProp,codTipoEndProp,logradouroProp,numeroProp,bairroLocalProp,UFCODProp,MUNCODProp,telFixo,telCel,nomeAnimal,codVetEspecie,idadeAnimal,codSexoAnimal,codPorte,raca,codLocalAcid,codSimNaoVacinado,codSimNaoCastrado,registro,condicaoObs,observaAnimal)" & _
    " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
            selcom.Parameters.Clear()
            selcom.Parameters.Add("@codSINA", OleDbType.VarChar, 100).Value = txtCodSina.Text
            selcom.Parameters.Add("@codSexoPac", OleDbType.VarChar, 50).Value = rblSexoPac.SelectedValue
            selcom.Parameters.Add("@dataNascPac", OleDbType.VarChar, 50).Value = txtDataNascPac.Text
            selcom.Parameters.Add("@UFCODPac", OleDbType.VarChar, 50).Value = ddlUFPac.SelectedValue
            selcom.Parameters.Add("@MUNCODPac", OleDbType.VarChar, 50).Value = ddlMunPac.SelectedValue
            selcom.Parameters.Add("@bairroPac", OleDbType.VarChar, 100).Value = txtBairroPac.Text
            selcom.Parameters.Add("@codVetOcupa", OleDbType.VarChar, 50).Value = rblVetOcup.SelectedValue
            selcom.Parameters.Add("@codTipoExp", OleDbType.VarChar, 50).Value = rblVetTipoExp.SelectedValue
            selcom.Parameters.Add("@codLocal", OleDbType.VarChar, 50).Value = rblVetLocalExposicao.SelectedValue
            selcom.Parameters.Add("@codFerimento", OleDbType.VarChar, 50).Value = rblVetFere.SelectedValue
            selcom.Parameters.Add("@codTipoFerim", OleDbType.VarChar, 50).Value = rblVetTipoFere.SelectedValue
            selcom.Parameters.Add("@dataExp", OleDbType.VarChar, 50).Value = txtDataExp.Text
            selcom.Parameters.Add("@observaPac", OleDbType.VarChar, 400).Value = txtObsPac.Text
            selcom.Parameters.Add("@nomePropr", OleDbType.VarChar, 300).Value = txtNomeProp.Text
            selcom.Parameters.Add("@sobrenomeProp", OleDbType.VarChar, 100).Value = txtSobreProp.Text
            selcom.Parameters.Add("@codSexoProp", OleDbType.VarChar, 50).Value = rblSexoProp.SelectedValue
            selcom.Parameters.Add("@dataNascimProp", OleDbType.VarChar, 50).Value = txtDataNascProp.Text
            selcom.Parameters.Add("@CodSituacaoProp", OleDbType.VarChar, 50).Value = rblSitProp.SelectedValue
            selcom.Parameters.Add("@codTipoEndProp", OleDbType.VarChar, 50).Value = rblTipoProp.SelectedValue
            selcom.Parameters.Add("@logradouroProp", OleDbType.VarChar, 300).Value = txtLograProp.Text
            selcom.Parameters.Add("@numeroProp", OleDbType.VarChar, 50).Value = txtNumProp.Text
            selcom.Parameters.Add("@bairroLocalProp", OleDbType.VarChar, 200).Value = txtBairroProp.Text
            selcom.Parameters.Add("@UFCODProp", OleDbType.VarChar, 50).Value = ddlUFProp.SelectedValue
            selcom.Parameters.Add("@MUNCODProp", OleDbType.VarChar, 50).Value = ddlMunProp.SelectedValue
            selcom.Parameters.Add("@telFixo", OleDbType.VarChar, 100).Value = txtTelFixoProp.Text
            selcom.Parameters.Add("@telCel", OleDbType.VarChar, 100).Value = txtTelCelProp.Text
            selcom.Parameters.Add("@nomeAnimal", OleDbType.VarChar, 300).Value = txtObsProp.Text
            selcom.Parameters.Add("@codVetEspecie", OleDbType.VarChar, 150).Value = txtNomeAnimal.Text
            selcom.Parameters.Add("@idadeAnimal", OleDbType.VarChar, 50).Value = rblEspecie.SelectedValue
            selcom.Parameters.Add("@codSexoAnimal", OleDbType.VarChar, 10).Value = txtIdade.Text
            selcom.Parameters.Add("@codPorte", OleDbType.VarChar, 50).Value = rblPorte.SelectedValue
            selcom.Parameters.Add("@raca", OleDbType.VarChar, 100).Value = txtRaca.Text
            selcom.Parameters.Add("@codLocalAcid", OleDbType.VarChar, 50).Value = rblLocalAcid.SelectedValue
            selcom.Parameters.Add("@codSimNaoVacinado", OleDbType.VarChar, 50).Value = rblVacinado.SelectedValue
            selcom.Parameters.Add("@codSimNaoCastrado", OleDbType.VarChar, 50).Value = rblCastrado.SelectedValue
            selcom.Parameters.Add("@registro", OleDbType.VarChar, 100).Value = txtRegistro.Text
            selcom.Parameters.Add("@condicaoObs", OleDbType.VarChar, 50).Value = rblCondObs.SelectedValue
            selcom.Parameters.Add("@observaAnimal", OleDbType.VarChar, 300).Value = txtObsAnim.Text
            Dim teste As Boolean
            Try
                teste = selcom.ExecuteNonQuery
            Catch ex As System.Data.OleDb.OleDbException
                Label6.Text = "Erro: " & ex.Message.ToString
                Return
            End Try
            conecte.Close()
            Label2.Text = "Registro inserido e gravado"
            txtCodSina.Focus()
            cargaGRID()
        End Sub


    • Editado Wilson Boris quinta-feira, 19 de julho de 2012 14:53 grafia
    quinta-feira, 19 de julho de 2012 14:52

Respostas

  • Valeu Lucas!

    Registro inserido e gravado com sucesso: Grande Fernando em pouco tempo alavancou o que estava patinando por um bom tempo. Abaixo o código perfeito, muito obrigado!

        Private Sub inserir()
            Dim conecte As New OleDbConnection
            conecte.ConnectionString = My.Settings.SIADSConecte
            Try
                conecte.Open()
            Catch ex As System.Data.OleDb.OleDbException
                Label1.Text = "Erro de conexao com o Banco de Dados: " & ex.Message.ToString
                Return
            End Try
            Dim selcom As New System.Data.OleDb.OleDbCommand
            selcom.Connection = conecte
            selcom.CommandText = "INSERT INTO tbVETAARH (codSINAN,codSexoPac,dataNascPac,UFCODPac,MUNCODPac,bairroPac,codVetOcupa,codTipoExp,codLocal,codFerimento,codTipoFerim,dataExp,observaPac,nomePropr,sobrenomeProp,codSexoProp,dataNascimProp,CodSituacaoProp,codTipoEndProp,logradouroProp,numeroProp,bairroLocalProp,UFCODProp,MUNCODProp,telFixo,telCel,nomeAnimal,codVetEspecie,idadeAnimal,codSexoAnimal,codPorte,raca,codLocalAcid,codSimNaoVacinado,codSimNaoCastrado,registro,condicaoObs,observaAnimal)" & _
                                  " VALUES(@codSINAN,@codSexoPac,@dataNascPac,@UFCODPac,@MUNCODPac,@bairroPac,@codVetOcupa,@codTipoExp,@codLocal,@codFerimento,@codTipoFerim,@dataExp,@observaPac,@nomePropr,@sobrenomeProp,@codSexoProp,@dataNascimProp,@CodSituacaoProp,@codTipoEndProp,@logradouroProp,@numeroProp,@bairroLocalProp,@UFCODProp,@MUNCODProp,@telFixo,@telCel,@nomeAnimal,@codVetEspecie,@idadeAnimal,@codSexoAnimal,@codPorte,@raca,@codLocalAcid,@codSimNaoVacinado,@codSimNaoCastrado,@registro,@condicaoObs,@observaAnimal)"
            selcom.Parameters.Clear()
            selcom.Parameters.Add("@codSINAN", OleDbType.Integer).Value = Convert.ToInt32(txtCodSinan.Text)
            selcom.Parameters.Add("@codSexoPac", OleDbType.Integer).Value = Convert.ToInt32(rblSexoPac.SelectedValue)
            selcom.Parameters.Add("@dataNascPac", OleDbType.VarChar).Value = txtDataNascPac.Text
            selcom.Parameters.Add("@UFCODPac", OleDbType.Integer).Value = Convert.ToInt32(ddlUFPac.SelectedValue)
            selcom.Parameters.Add("@MUNCODPac", OleDbType.Integer).Value = Convert.ToInt32(ddlMunPac.SelectedValue)
            selcom.Parameters.Add("@bairroPac", OleDbType.VarChar).Value = txtBairroPac.Text
            selcom.Parameters.Add("@codVetOcupa", OleDbType.Integer).Value = Convert.ToInt32(rblVetOcup.SelectedValue)
            selcom.Parameters.Add("@codTipoExp", OleDbType.Integer).Value = Convert.ToInt32(rblVetTipoExp.SelectedValue)
            selcom.Parameters.Add("@codLocal", OleDbType.Integer).Value = Convert.ToInt32(rblVetLocalExposicao.SelectedValue)
            selcom.Parameters.Add("@codFerimento", OleDbType.Integer).Value = Convert.ToInt32(rblVetFere.SelectedValue)
            selcom.Parameters.Add("@codTipoFerim", OleDbType.Integer).Value = Convert.ToInt32(rblVetTipoFere.SelectedValue)
            selcom.Parameters.Add("@dataExp", OleDbType.VarChar).Value = txtDataExp.Text
            selcom.Parameters.Add("@observaPac", OleDbType.VarChar).Value = txtObsPac.Text
            selcom.Parameters.Add("@nomePropr", OleDbType.VarChar).Value = txtNomeProp.Text
            selcom.Parameters.Add("@sobrenomeProp", OleDbType.VarChar).Value = txtSobreProp.Text
            selcom.Parameters.Add("@codSexoProp", OleDbType.Integer).Value = Convert.ToInt32(rblSexoProp.SelectedValue)
            selcom.Parameters.Add("@dataNascimProp", OleDbType.VarChar).Value = txtDataNascProp.Text
            selcom.Parameters.Add("@CodSituacaoProp", OleDbType.Integer).Value = Convert.ToInt32(rblSitProp.SelectedValue)
            selcom.Parameters.Add("@codTipoEndProp", OleDbType.Integer).Value = Convert.ToInt32(rblTipoProp.SelectedValue)
            selcom.Parameters.Add("@logradouroProp", OleDbType.VarChar).Value = txtLograProp.Text
            selcom.Parameters.Add("@numeroProp", OleDbType.VarChar).Value = txtNumProp.Text
            selcom.Parameters.Add("@bairroLocalProp", OleDbType.VarChar).Value = txtBairroProp.Text
            selcom.Parameters.Add("@UFCODProp", OleDbType.Integer).Value = Convert.ToInt32(ddlUFProp.SelectedValue)
            selcom.Parameters.Add("@MUNCODProp", OleDbType.Integer).Value = Convert.ToInt32(ddlMunProp.SelectedValue)
            selcom.Parameters.Add("@telFixo", OleDbType.VarChar).Value = txtTelFixoProp.Text
            selcom.Parameters.Add("@telCel", OleDbType.VarChar).Value = txtTelCelProp.Text
            selcom.Parameters.Add("@nomeAnimal", OleDbType.VarChar).Value = txtObsProp.Text
            selcom.Parameters.Add("@codVetEspecie", OleDbType.Integer).Value = Convert.ToInt32(rblEspecie.SelectedValue)
            selcom.Parameters.Add("@idadeAnimal", OleDbType.VarChar).Value = txtIdade.Text
            selcom.Parameters.Add("@codSexoAnimal", OleDbType.Integer).Value = Convert.ToInt32(txtIdade.Text)
            selcom.Parameters.Add("@codPorte", OleDbType.Integer).Value = Convert.ToInt32(rblPorte.SelectedValue)
            selcom.Parameters.Add("@raca", OleDbType.VarChar).Value = txtRaca.Text
            selcom.Parameters.Add("@codLocalAcid", OleDbType.Integer).Value = Convert.ToInt32(rblLocalAcid.SelectedValue)
            selcom.Parameters.Add("@codSimNaoVacinado", OleDbType.Integer).Value = Convert.ToInt32(rblVacinado.SelectedValue)
            selcom.Parameters.Add("@codSimNaoCastrado", OleDbType.Integer).Value = Convert.ToInt32(rblCastrado.SelectedValue)
            selcom.Parameters.Add("@registro", OleDbType.VarChar).Value = txtRegistro.Text
            selcom.Parameters.Add("@condicaoObs", OleDbType.Integer).Value = Convert.ToInt32(rblCondObs.SelectedValue)
            selcom.Parameters.Add("@observaAnimal", OleDbType.VarChar).Value = txtObsAnim.Text
            Dim teste As Boolean
            Try
                teste = selcom.ExecuteNonQuery
            Catch ex As System.Data.OleDb.OleDbException
                Label6.Text = "Erro: " & ex.Message.ToString
                Return
            End Try
            conecte.Close()
            Label2.Text = "Registro inserido e gravado"
            txtCodSinan.Focus()
            cargaGRID()
        End Sub
    • Marcado como Resposta Wilson Boris sexta-feira, 20 de julho de 2012 16:02
    sexta-feira, 20 de julho de 2012 16:02

Todas as Respostas

  • Amigo,

    Já tentou tirar o TRY-Catch e executar o código?
    Acredito que a descrição do erro será muito mais completa!

    Espero ter ajudado!


    Não esqueça de marcar como útil uma resposta que te ajude.
    "A diversão é a alma do negócio"

    sexta-feira, 20 de julho de 2012 12:54
  • Valeu Lucas!

    Registro inserido e gravado com sucesso: Grande Fernando em pouco tempo alavancou o que estava patinando por um bom tempo. Abaixo o código perfeito, muito obrigado!

        Private Sub inserir()
            Dim conecte As New OleDbConnection
            conecte.ConnectionString = My.Settings.SIADSConecte
            Try
                conecte.Open()
            Catch ex As System.Data.OleDb.OleDbException
                Label1.Text = "Erro de conexao com o Banco de Dados: " & ex.Message.ToString
                Return
            End Try
            Dim selcom As New System.Data.OleDb.OleDbCommand
            selcom.Connection = conecte
            selcom.CommandText = "INSERT INTO tbVETAARH (codSINAN,codSexoPac,dataNascPac,UFCODPac,MUNCODPac,bairroPac,codVetOcupa,codTipoExp,codLocal,codFerimento,codTipoFerim,dataExp,observaPac,nomePropr,sobrenomeProp,codSexoProp,dataNascimProp,CodSituacaoProp,codTipoEndProp,logradouroProp,numeroProp,bairroLocalProp,UFCODProp,MUNCODProp,telFixo,telCel,nomeAnimal,codVetEspecie,idadeAnimal,codSexoAnimal,codPorte,raca,codLocalAcid,codSimNaoVacinado,codSimNaoCastrado,registro,condicaoObs,observaAnimal)" & _
                                  " VALUES(@codSINAN,@codSexoPac,@dataNascPac,@UFCODPac,@MUNCODPac,@bairroPac,@codVetOcupa,@codTipoExp,@codLocal,@codFerimento,@codTipoFerim,@dataExp,@observaPac,@nomePropr,@sobrenomeProp,@codSexoProp,@dataNascimProp,@CodSituacaoProp,@codTipoEndProp,@logradouroProp,@numeroProp,@bairroLocalProp,@UFCODProp,@MUNCODProp,@telFixo,@telCel,@nomeAnimal,@codVetEspecie,@idadeAnimal,@codSexoAnimal,@codPorte,@raca,@codLocalAcid,@codSimNaoVacinado,@codSimNaoCastrado,@registro,@condicaoObs,@observaAnimal)"
            selcom.Parameters.Clear()
            selcom.Parameters.Add("@codSINAN", OleDbType.Integer).Value = Convert.ToInt32(txtCodSinan.Text)
            selcom.Parameters.Add("@codSexoPac", OleDbType.Integer).Value = Convert.ToInt32(rblSexoPac.SelectedValue)
            selcom.Parameters.Add("@dataNascPac", OleDbType.VarChar).Value = txtDataNascPac.Text
            selcom.Parameters.Add("@UFCODPac", OleDbType.Integer).Value = Convert.ToInt32(ddlUFPac.SelectedValue)
            selcom.Parameters.Add("@MUNCODPac", OleDbType.Integer).Value = Convert.ToInt32(ddlMunPac.SelectedValue)
            selcom.Parameters.Add("@bairroPac", OleDbType.VarChar).Value = txtBairroPac.Text
            selcom.Parameters.Add("@codVetOcupa", OleDbType.Integer).Value = Convert.ToInt32(rblVetOcup.SelectedValue)
            selcom.Parameters.Add("@codTipoExp", OleDbType.Integer).Value = Convert.ToInt32(rblVetTipoExp.SelectedValue)
            selcom.Parameters.Add("@codLocal", OleDbType.Integer).Value = Convert.ToInt32(rblVetLocalExposicao.SelectedValue)
            selcom.Parameters.Add("@codFerimento", OleDbType.Integer).Value = Convert.ToInt32(rblVetFere.SelectedValue)
            selcom.Parameters.Add("@codTipoFerim", OleDbType.Integer).Value = Convert.ToInt32(rblVetTipoFere.SelectedValue)
            selcom.Parameters.Add("@dataExp", OleDbType.VarChar).Value = txtDataExp.Text
            selcom.Parameters.Add("@observaPac", OleDbType.VarChar).Value = txtObsPac.Text
            selcom.Parameters.Add("@nomePropr", OleDbType.VarChar).Value = txtNomeProp.Text
            selcom.Parameters.Add("@sobrenomeProp", OleDbType.VarChar).Value = txtSobreProp.Text
            selcom.Parameters.Add("@codSexoProp", OleDbType.Integer).Value = Convert.ToInt32(rblSexoProp.SelectedValue)
            selcom.Parameters.Add("@dataNascimProp", OleDbType.VarChar).Value = txtDataNascProp.Text
            selcom.Parameters.Add("@CodSituacaoProp", OleDbType.Integer).Value = Convert.ToInt32(rblSitProp.SelectedValue)
            selcom.Parameters.Add("@codTipoEndProp", OleDbType.Integer).Value = Convert.ToInt32(rblTipoProp.SelectedValue)
            selcom.Parameters.Add("@logradouroProp", OleDbType.VarChar).Value = txtLograProp.Text
            selcom.Parameters.Add("@numeroProp", OleDbType.VarChar).Value = txtNumProp.Text
            selcom.Parameters.Add("@bairroLocalProp", OleDbType.VarChar).Value = txtBairroProp.Text
            selcom.Parameters.Add("@UFCODProp", OleDbType.Integer).Value = Convert.ToInt32(ddlUFProp.SelectedValue)
            selcom.Parameters.Add("@MUNCODProp", OleDbType.Integer).Value = Convert.ToInt32(ddlMunProp.SelectedValue)
            selcom.Parameters.Add("@telFixo", OleDbType.VarChar).Value = txtTelFixoProp.Text
            selcom.Parameters.Add("@telCel", OleDbType.VarChar).Value = txtTelCelProp.Text
            selcom.Parameters.Add("@nomeAnimal", OleDbType.VarChar).Value = txtObsProp.Text
            selcom.Parameters.Add("@codVetEspecie", OleDbType.Integer).Value = Convert.ToInt32(rblEspecie.SelectedValue)
            selcom.Parameters.Add("@idadeAnimal", OleDbType.VarChar).Value = txtIdade.Text
            selcom.Parameters.Add("@codSexoAnimal", OleDbType.Integer).Value = Convert.ToInt32(txtIdade.Text)
            selcom.Parameters.Add("@codPorte", OleDbType.Integer).Value = Convert.ToInt32(rblPorte.SelectedValue)
            selcom.Parameters.Add("@raca", OleDbType.VarChar).Value = txtRaca.Text
            selcom.Parameters.Add("@codLocalAcid", OleDbType.Integer).Value = Convert.ToInt32(rblLocalAcid.SelectedValue)
            selcom.Parameters.Add("@codSimNaoVacinado", OleDbType.Integer).Value = Convert.ToInt32(rblVacinado.SelectedValue)
            selcom.Parameters.Add("@codSimNaoCastrado", OleDbType.Integer).Value = Convert.ToInt32(rblCastrado.SelectedValue)
            selcom.Parameters.Add("@registro", OleDbType.VarChar).Value = txtRegistro.Text
            selcom.Parameters.Add("@condicaoObs", OleDbType.Integer).Value = Convert.ToInt32(rblCondObs.SelectedValue)
            selcom.Parameters.Add("@observaAnimal", OleDbType.VarChar).Value = txtObsAnim.Text
            Dim teste As Boolean
            Try
                teste = selcom.ExecuteNonQuery
            Catch ex As System.Data.OleDb.OleDbException
                Label6.Text = "Erro: " & ex.Message.ToString
                Return
            End Try
            conecte.Close()
            Label2.Text = "Registro inserido e gravado"
            txtCodSinan.Focus()
            cargaGRID()
        End Sub
    • Marcado como Resposta Wilson Boris sexta-feira, 20 de julho de 2012 16:02
    sexta-feira, 20 de julho de 2012 16:02