Syntax error in SELECT WHERE using ADO.Net parameters

Asked

Viewed 323 times

1

Someone understands this mistake and gets a solution?

ERRO DE SINTAXE

Code:

OleDbConnection ConSelect = new OleDbConnection();
ConSelect.ConnectionString = Properties.Settings.Default.dbInvoice;

ConSelect.Open();
OleDbCommand CmmSelect = new OleDbCommand();

CmmSelect.CommandText = "SELECT Qtd, UnitPriceInv FROM JAN WHERE EmgPartInv = ? AND CodCliInv = ? AND InvoiceName = ? ";
CmmSelect.Parameters.Add("@EmgPart", OleDbType.VarChar, 10).Value = txtEmg.Text;
CmmSelect.Parameters.Add("@CodCli", OleDbType.Integer, 18).Value = txtCodCli.Text;
CmmSelect.Parameters.Add("@Invoice", OleDbType.VarChar, 15).Value = label45.Text;

CmmSelect.CommandType = CommandType.Text;
CmmSelect.Connection = ConSelect;
OleDbDataReader DRSelectCond;
DRSelectCond = CmmSelect.ExecuteReader();
DRSelectCond.Read();

2 answers

5


It looks simple, replace the commas with AND:

"... EmgPartInv = ? AND CondCliInv=? AND InvoiceName = ?"

Next to "No value Given for one or more required Parameters." Are you saying that there is no value for the parameter, change its query for:

CmmSelect.CommandText = "SELECT Qtd, UnitPriceInv FROM JAN WHERE EmgPartInv = @EmgPart AND CodCliInv = @CodCli AND InvoiceName = @Invoice ";
CmmSelect.Parameters.Add("@EmgPart", OleDbType.VarChar, 10).Value = txtEmg.Text;
CmmSelect.Parameters.Add("@CodCli", OleDbType.Integer, 18).Value = txtCodCli.Text;
CmmSelect.Parameters.Add("@Invoice", OleDbType.VarChar, 15).Value = label45.Text;
  • Progress has been made, but the error has changed to: Additional information: No value given for one or more required parameters.

  • And then, when in the last case, I put the result values directly in Syntax.. the error is also another: Additional information: Erro de sintaxe (operador faltando) na expressão de consulta 'EmgPartInv = bt 234 AND CodCliInv = 1 AND InvoiceName = INV123'.

  • 1

    @Mauríciosanches What the hell is "Bt 234"? - I would suggest testing the separate query directly in the DB, and then applying in the code, otherwise it is difficult.

  • With the edition that the, the syntax worked. and with the recommendation of @Bacco I discovered an error in the syntax using Query direct in DB. the QTD parameter should actually be Qtdinv. Thanks.

4

Browser other questions tagged

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