Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “FROM子句中的语法错误”在C中使用OleDb,但在Access本身中对同一查询没有错误_C#_Sql_Ms Access_Oledbdatareader_Oledbexception - Fatal编程技术网

C# “FROM子句中的语法错误”在C中使用OleDb,但在Access本身中对同一查询没有错误

C# “FROM子句中的语法错误”在C中使用OleDb,但在Access本身中对同一查询没有错误,c#,sql,ms-access,oledbdatareader,oledbexception,C#,Sql,Ms Access,Oledbdatareader,Oledbexception,在c/OleDbCommand.ExecuteReader中使用以下SQL语句时,FROM子句中出现语法错误。 在MS Access中直接使用完全相同的语句可以很好地工作 SELECT s.idShots, s.shotdata, c.[original], s.[hash], comp.idCompetitions, comp.competitionsname, sh.idShooters, sh.firstname, sh.lastname FROM (([Shots] s INNER

在c/OleDbCommand.ExecuteReader中使用以下SQL语句时,FROM子句中出现语法错误。 在MS Access中直接使用完全相同的语句可以很好地工作

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
在c内:

        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连接工作正常,在以前的一些命令中使用过,一切正常


谢谢你的建议

我让它工作了。。。无可奉告:/

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

我让它工作了。。。无可奉告:/

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

为了记录在案,问题是COMP被包括在访问DDL的列表中,可能是作为accessddl压缩的缩写。将表别名从comp更改为cmpt允许查询在System.Data.OleDb下成功运行:

sql=从中选择s.idShots、s.shotdata、c.[原始]、s.[哈希]、cmpt.idCompetitions、cmpt.competitionname、sh.idShooters、sh.firstname、sh.lastname+ [镜头]s+ c.[uuid]=s.[uuid]上的内部联接[ShotsCertificate]c+ 内部连接[Competitions]cmpt上的cmpt.idCompetitions=s.fidCompetitions+ 内部联接[Shooters]sh ON sh.idShooters=s.fidShooters+ s.idShots ASC订购;
为了记录在案,问题是COMP被包括在访问DDL的列表中,可能是作为accessddl压缩的缩写。将表别名从comp更改为cmpt允许查询在System.Data.OleDb下成功运行:

sql=从中选择s.idShots、s.shotdata、c.[原始]、s.[哈希]、cmpt.idCompetitions、cmpt.competitionname、sh.idShooters、sh.firstname、sh.lastname+ [镜头]s+ c.[uuid]=s.[uuid]上的内部联接[ShotsCertificate]c+ 内部连接[Competitions]cmpt上的cmpt.idCompetitions=s.fidCompetitions+ 内部联接[Shooters]sh ON sh.idShooters=s.fidShooters+ s.idShots ASC订购;
[Shots]、[ShotsCertificate]、[Competitions]和[Shooters]是否都是表,或者其中一个或多个是Access中保存的select查询?请尝试使用与以前一样的别名。所有表都是普通表,没有视图或something@Gustav:在每个表之后尝试AS,但行为仍然相同:在ms access中工作,在executeReaderAre[Shots]中引发异常,[射击证书],[比赛]和[射击运动员]所有表,或者其中一个或多个表是Access中保存的select查询?请尝试使用别名之前的名称。所有表都是普通表,没有视图或名称something@Gustav:在每个表之后使用AS进行了尝试,但行为仍然相同:在ms access中工作,使用executeReaderThank引发异常谢谢!有没有办法获取更精确的错误消息?谢谢!有吗有没有办法获得更精确的错误消息?