Syntax error in SELECT WHERE using ADO.Net parameters [closed]

1

Does anyone understand this error and get a solution?

Code:

OleDbConnectionConSelect=newOleDbConnection();ConSelect.ConnectionString=Properties.Settings.Default.dbInvoice;ConSelect.Open();OleDbCommandCmmSelect=newOleDbCommand();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();
    
asked by anonymous 29.08.2016 / 18:09

2 answers

5

It seems simple, replace the commas with AND :

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

Next for "No value given for one or more required parameters." You're saying there's no pro-parameter value, change your query to:

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;
    
29.08.2016 / 18:13
4

This will make it right:

"SELECT Qtd, UnitPriceInv FROM JAN WHERE EmgPartInv = @EmgPart AND CodCliInv = @CodCli AND InvoiceName = @Invoice"

Documentation .

    
29.08.2016 / 18:32