SQL query for Access.MDB file doesn't work,F1

A

AleXmanFree

Hello World.
I have code that connects to Access file (.mdb) and executing query
that returnst table to my code, it has no matter here but code is on
C#, and the final point for the query result is
dbDataAdapter.Fill(tbl);
before this Fill(tbl) method my code dynamically generates SQL query
string , and depending on how many comboboxes user has selected so much
criterias and lines are added to query string, the problem is that in
cases when user selects 2 Languages (comboBoxes) query runs as should,
but when it is more then 2 languages the query raises Exception: Syntax
error (missing operator) in query expression ''. , but amazing for me
that this new generated SQL query that raises exception works correctly
if i run it in ms Sql, so query that generates my code syntactically is
right. SO i cant find the reason why it raises exception in code, i
think here something connected with Access file
distinctive feature that I dont know well here is queries example for 2
and 3 languages cases:

SQL for 2 languages:
SELECT Dictionary.[Text] AS Lang_0, Dictionary1.[Text] AS Lang_1
FROM Dictionary INNER JOIN
Dictionary Dictionary1 ON Dictionary.GroupID = Dictionary1.GroupID
AND Dictionary.LanguageCode <> Dictionary1.LanguageCode
WHERE (Dictionary.LanguageCode = 'en-us') AND (Dictionary1.LanguageCode
= 'fr-fr')
ORDER BY Dictionary.GroupID;

SQL for 3 languages:
SELECT
Dictionary.[Text] AS Lang_0,
Dictionary1.[Text] AS Lang_1,
Dictionary2.[Text] AS Lang_2
FROM Dictionary
INNER JOIN
Dictionary Dictionary1 ON Dictionary.GroupID = Dictionary1.GroupID
AND Dictionary.LanguageCode <> Dictionary1.LanguageCode
INNER JOIN
Dictionary Dictionary2 ON Dictionary.GroupID = Dictionary2.GroupID
AND Dictionary.LanguageCode <> Dictionary2.LanguageCode

WHERE
(Dictionary.LanguageCode = 'de-de') AND
(Dictionary1.LanguageCode = 'el') AND
(Dictionary2.LanguageCode = 'it-it')
ORDER BY Dictionary.GroupID;
 
A

AleXmanFree

Well I have already found the reason, scopes must be given so:

SQL Query for 4 Languges:

SELECT Dictionary.[Text] AS Lang_0, Dictionary1.[Text] AS Lang_1,
Dictionary2.[Text] AS Lang_2, Dictionary3.[Text] AS Lang_3
FROM (((Dictionary
INNER JOIN
Dictionary Dictionary1 ON Dictionary.GroupID = Dictionary1.GroupID AND
Dictionary.LanguageCode <> Dictionary1.LanguageCode)
INNER JOIN
Dictionary Dictionary2 ON Dictionary.GroupID = Dictionary2.GroupID AND
Dictionary.LanguageCode <> Dictionary2.LanguageCode)
INNER JOIN
Dictionary Dictionary3 ON Dictionary.GroupID = Dictionary3.GroupID AND
Dictionary.LanguageCode <> Dictionary3.LanguageCode)

WHERE (Dictionary.LanguageCode = 'en-us') AND
(Dictionary1.LanguageCode = 'fr-fr') AND
(Dictionary2.LanguageCode = 'it-it') AND
(Dictionary3.LanguageCode = 'ru-ru')

ORDER BY Dictionary.GroupID


SQL Query for 3 Languages:

SELECT Dictionary.Text AS FirstLang, Dictionary_1.Text AS
SecondLang, Dictionary_2.Text AS ThirdLang
FROM ((Dictionary INNER JOIN
Dictionary Dictionary_1 ON Dictionary.GroupID = Dictionary_1.GroupID
AND Dictionary.LanguageCode <> Dictionary_1.LanguageCode)
INNER JOIN
Dictionary Dictionary_2 ON Dictionary.GroupID = Dictionary_2.GroupID
AND Dictionary.LanguageCode <> Dictionary_2.LanguageCode)
WHERE
(Dictionary.LanguageCode = 'en-us') AND (Dictionary_1.LanguageCode =
'ru-ru') AND (Dictionary_2.LanguageCode = 'fr-fr')
ORDER BY Dictionary.GroupID


SQL Query for 2 Languages:
in this case scopes are nt necessary but for example:

SELECT Dictionary.Text AS FirstLang, Dictionary_1.Text AS
SecondLang
FROM (Dictionary INNER JOIN
Dictionary Dictionary_1 ON Dictionary.GroupID = Dictionary_1.GroupID
AND Dictionary.LanguageCode <> Dictionary_1.LanguageCode)
WHERE (Dictionary.LanguageCode = 'en') AND
(Dictionary_1.LanguageCode = 'ru')
ORDER BY Dictionary.GroupID
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top