Dataset with cloister Where like '%' @parametro Visual Basic 2012

Asked

Viewed 239 times

2

Hello, I am creating a form to generate reports using the Reportviwer control and I came across a problem, I have a Dataset created with Dsclient name, I created a clausa to filter the search (Dataset Configuration)at the end of the Dataset query adds the following clause:

WHERE cliente_cnpj LIKE '%' + @clienteCnpj + '%'

where the @Clientecnpj parameter comes from a textbox, but when I finish an error occurs, saying that the syntax near @client is wrong, but I do not find the error!

Thanks in advance!
this is the code of the form:

 Private Sub btnBuscar_Click(sender As Object, e As EventArgs) Handles btnBuscar.Click
    Me.clienteTableAdapter.Fill(Me.testebaseDataSet1.cliente,TextBox1.Text)
    Me.ReportViewer1.RefreshReport()
End Sub

I added the Reportviwer controls, when I added it he asked me to create a Dataset, I created the Dataset I selected the tables, everything working perfect, I opened the Dataset in Vb where he put the table I added, I selected Configure where opened a window with the query they are running:

SELECT cod_cliente, cliente_razaosocial, cliente_cnpj, cliente_cpf, cliente_codPraca, cliente_tipo, cliente_isencao, cliente_Redespacho, cliente_bloqueioCadastro, 
                     cliente_fantasia, cliente_ColetaCidade, cliente_ColetaBairro, cliente_ColetaUf, cliente_ColetaCep, cliente_ColetaHorario, cliente_ColetaEndereco, 
                     cliente_ExpedicaoBairro, cliente_ExpedicaoCep, cliente_ExpedicaoContato, cliente_ExpedicaoSigla, cliente_ExpedicaoObs, cliente_ExpedicaoData, 
                     cliente_ExpedicaoTelefone, cliente_ExpedicaoEndereco, cliente_ExpedicaoCidade, cliente_ExpedicaoRamal, cliente_ExpedicaoEmail, cliente_ExpedicaoFax, 
                     cliente_ExpedicaoColeta, cliente_ExpedicaoFormaCalculo, cliente_ExpedicaoUf, cliente_ExpedicaoZona, cliente_ExpedicaoMercEspecial, cliente_msgColeta, 
                     cliente_msgExpedicao, cliente_msgCotacao, cod_cotacao, cliente_cobrancaEndereco, cliente_cobrancaBairro, cliente_cobrancaCidade, cliente_cobrancaContato, 
                     cliente_cobrancaCadastrado, cliente_cobrancaTelefone, cliente_cobrancaCalculo, cliente_cobrancaDataCobranca, cliente_cobrancaFinalizado, 
                     cliente_cobrancaEmissao, cliente_cobrancaDataVEncimento, cliente_cobrancaSituacao, cliente_cobrancaUf, cliente_cobrancaObs, cliente_cobrancaUltimaAlteracao, 
                     cliente_cobrancaCep, cliente_inscricaoEstado, cliente_ColetaNumero, cliente_ZONA, cliente_cep, cliente_uf, cliente_numero, cliente_Bairro, cliente_Endereco, 
                     cliente_Cidade, cliente_telefone, cliente_contato FROM cliente

at the end I added the line WHERE cod_cliente LIKE '%' + @clienteCnpj + '%' when I click Finish it error saying it has error in syntax =\

  • @clienteCnpj indicates that you will enter a parameter in your query, it can better describe your problem?

  • @Marconi I followed these steps video classroom but in the cloister where of error...

  • Describe your problem better and try adding more snippets of code, which you actually tried.

  • @Marconi were those steps I made.

  • I Hebert. If you solved the problem, even if totally changing the code, it would be nice to post below a reply explaining how you did it. So future visitors to this page can benefit from your solution. Thank you!

2 answers

0

I am basing myself on the following reply from Soen

remove the % of your consultation:

WHERE cod_cliente LIKE @clienteCnpj

Then add them when adding the parameters:

sqlCommand.Parameters.AddWithValue("@clienteCnpj", "%" + clienteCnpj + "%");
  • the report created these lines: Me.clienteTableAdapter.Fill(Me.testebaseDataSet1.cliente,'Paremetro Aqui' and Me.ReportViewer1.RefreshReport() within the load function, I created a button and in the click button function I put Me.clienteTableAdapter.Fill(Me.testebaseDataSet1.cliente, "%" + TextBox1.Text + "%") as passed me more did not give, says that The conversion of the string '%18% ' in the type 'Integer' is not valid, so the % goes to the clause in the dataset settings =)

  • @Hebertdelima Cara, by the error you gave is pq the column is of the whole type, or the parameter is of the whole type, you will not be able to use a Where this way. Probably your parameter is with the wrong type

  • @Andrade went to check and yes the error had occurred because of this, the parameter was of one type and the value of another, but I already fixed was a detail that I did not realize, but still the syntax error continues, I’ve tried everything, is there any way to create this filter without using Dataset? thank you very much beast!

0

You need to see in the @Tobymosque reply whether Where is doing with the right fields probably your cod_client is int and the cliente_cnpj must be string.

That one

WHERE cod_cliente LIKE @clienteCnpj 

or

WHERE cliente_cnpj LIKE @clienteCnpj 

Browser other questions tagged

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