DataSet with clausa where like '%' @parametro Visual Basic 2012

2

Hello, I am creating a form to generate a report using the ReportViwer control and I came across a problem, I have a DataSet created with the name of ClientD, I created a clause to filter the search (DataSet Configuration), at the end of the DataSet query adds the following clause:

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

where the parameter @CentralCnpj comes from a textbox, but at the time I finish it an error occurs, saying that the syntax near the client is wrong, but I can not find the error!

Thank you! This is the form code:

 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 it asked me to create a DataSet, I created the DataSet I selected the tables, everything working perfect, I opened the DataSet in vb it where it put the table that 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 on finish it from error saying it has syntax error = \

    
asked by anonymous 01.04.2015 / 18:35

2 answers

0

I'm basing myself on the following response from SOen

Remove the % from your query:

WHERE cod_cliente LIKE @clienteCnpj

Then add them by adding the parameters:

sqlCommand.Parameters.AddWithValue("@clienteCnpj", "%" + clienteCnpj + "%");
    
01.04.2015 / 18:42
0

You need to see in @TobyMosque's response if the where is doing with the right fields is probably your client_code is int and the client_cnpj should be string.

This

WHERE cod_cliente LIKE @clienteCnpj 

or

WHERE cliente_cnpj LIKE @clienteCnpj 
    
01.04.2015 / 21:12