2017-02-16 5 views
1

次のSQL文を使用すると、FROM句に構文エラーが発生します。 MS Accessでまったく同じステートメントを使用すると、正常に動作します。 C#の内C#でOleDbを使用しても、Access自体で同じクエリでエラーが発生しない "FROM句の構文エラー"

SELECT 
s.idShots, s.shotdata, c.[original], s.[hash], comp.idCompetitions, comp.competitionsname, sh.idShooters, sh.firstname, sh.lastname 
FROM (([Shots] s 
INNER JOIN [ShotsCertificate] c ON c.[uuid] = s.[uuid]) 
INNER JOIN [Competitions] comp ON comp.idCompetitions = s.fidCompetitions) 
INNER JOIN [Shooters] sh ON sh.idShooters = s.fidShooters ORDER BY s.idShots ASC 

 OleDbCommand cmd2 = new OleDbCommand("", dbc); 
     cmd2.CommandText = "SELECT s.idShots, s.shotdata, c.[original], s.[hash], comp.idCompetitions, comp.competitionsname, sh.idShooters, sh.firstname, sh.lastname FROM" + 
      " (([Shots] s" + 
      " INNER JOIN [ShotsCertificate] c ON c.[uuid] = s.[uuid])" + 
      " INNER JOIN [Competitions] comp ON comp.idCompetitions = s.fidCompetitions)" + 
      " INNER JOIN [Shooters] sh ON sh.idShooters = s.fidShooters" + 
      " ORDER BY s.idShots ASC"; 

     log.Debug(cmd2.CommandText); 
     OleDbDataReader r = cmd2.ExecuteReader(); 

DBC接続が正常に動作し、それはいくつかの以前のコマンドと、すべての作品に使われています。

お寄せいただきありがとうございます!

+0

は[ショット]、[ShotsCertificate]、[大会]、および[シューターズ]すべてのテーブルにいる、または1つですAccessでセーブされた選択クエリを保存していますか? –

+0

エイリアスの前に 'As'を使ってみてください。ありがとうのExecuteReader – Gustav

+0

すべては、何の見解か何か – Christopher

答えて

0

、問題はCOMPはおそらくアクセスDDLためCOMPRESSIONの省略形として、Access SQL Reserved Wordsのリストに含まれていることではなかったです。 compからcmptに表の別名を変更すると、クエリがSystem.Data.OleDbのもとで正常に実行することができ:

sql = "SELECT s.idShots, s.shotdata, c.[original], s.[hash], cmpt.idCompetitions, cmpt.competitionsname, sh.idShooters, sh.firstname, sh.lastname FROM" + 
    " (([Shots] s" + 
    " INNER JOIN [ShotsCertificate] c ON c.[uuid] = s.[uuid])" + 
    " INNER JOIN [Competitions] cmpt ON cmpt.idCompetitions = s.fidCompetitions)" + 
    " INNER JOIN [Shooters] sh ON sh.idShooters = s.fidShooters" + 
    " ORDER BY s.idShots ASC"; 
+0

で例外をスローし、MSアクセスでの作品:まだ同じ動作、各テーブルの後に「AS」を試してみました: – Christopher

0

私はそれが働いてしまった...ノーコメント:記録のために/

SELECT 
[Shots].[idShots], [Shots].[shotdata], [ShotsCertificate].[original], [Shots].[hash], [Competitions].[idCompetitions], [Competitions].[competitionsname], [Shooters].[idShooters], [Shooters].[firstname], [Shooters].[lastname] 
FROM (([Shots] 
    INNER JOIN [ShotsCertificate] ON [ShotsCertificate].[uuid] = [Shots].[uuid]) 
    INNER JOIN [Competitions] ON [Competitions].[idCompetitions] = [Shots].[fidCompetitions]) 
    INNER JOIN [Shooters] ON [Shooters].[idShooters] = [Shots].[fidShooters] 
ORDER BY [Shots].[idShots] ASC 
関連する問題