1

Error message as screenshot

Hello! I tried to connect 4 tables form Access in Visual Basic c# and I got "Syntax error (missing operator) in query expression", can you please help me? Thanks!

string query = "Select e.Denumire_Ech, e.Descriere_Ech, e.UnitateMasura, e.Pret_Vanzare, o.Cantitate_EchOf From ECHIPAMENTE e INNER JOIN OFERTE o ON e.Cod_Echipament = o.Cod_Echipament INNER JOIN CONTRACTE c ON c.Cod_Oferta = o.Cod_Oferta INNER JOIN FACTURI f ON f.Nr_Contract = c.Nr_Contract WHERE Nr_Contract='" + CB_Contract.Text + "'";
4
  • 1
    You should really edit the error into your question instead of showing an image. However, it could be that your query string is too long for your provider to handle (Because of the note in the error message). You could try using some newlines between filters/statements. Also note that you are open to SQL injection attacks. Commented Jun 26, 2018 at 13:58
  • 1
    Your where clause says WHERE Nr_Contract=... but you don't specify which table, and you have multiple columns with that name. Commented Jun 26, 2018 at 13:59
  • 1
    Also, if CB_Contract.Text contains any unusual text, your query will fail. Commented Jun 26, 2018 at 14:01
  • off-topic but as @Silvermind said, you are open to SQL injection attacks. You should look into prepared statements Commented Jun 26, 2018 at 14:02

1 Answer 1

1

You have multiple tables you are joining across but have not specified which table your WHERE clause is looking up on.

string query = "Select e.Denumire_Ech, e.Descriere_Ech, e.UnitateMasura, e.Pret_Vanzare, o.Cantitate_EchOf From ECHIPAMENTE e INNER JOIN OFERTE o ON e.Cod_Echipament = o.Cod_Echipament INNER JOIN CONTRACTE c ON c.Cod_Oferta = o.Cod_Oferta INNER JOIN FACTURI f ON f.Nr_Contract = c.Nr_Contract WHERE c.Nr_Contract='" + CB_Contract.Text + "'";

Also you should watch out for SQL injection and unusual characters in the CB_Contract.Text For example if there is a ' character then the sql will fail.

Sign up to request clarification or add additional context in comments.

1 Comment

So, everything I said in the comments?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.