' FROM子句中的语法错误'或' JOIN操作中的语法错误'加入两个CSV文件时

时间:2016-11-06 10:07:30

标签: sql csv ms-access jet

我有两个带有棒球统计数据的CSV文件,我试图加入如下,

strncpy

我已经编写了一个C#函数来使用Jet进行连接。我查询单个表格没有任何问题(示例查询SELECT Master.playerID, Batting.RBI FROM ([Master.csv] INNER JOIN [Batting.csv]) ON (Master.playerID=Batting.playerID) 工作正常),但由于某种原因,它不喜欢连接。

是因为SELECT COUNT(playerId) FROM [Master.csv]Master表无法识别吗?

我附带的C#代码的相关位,

Batting

string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties='text;HDR=Yes;FMT=Delimited;';"; OleDbConnection conn = new OleDbConnection(constr); OleDbCommand command = new OleDbCommand(SQLStatement, conn); conn.Open(); OleDbDataAdapter sda = new OleDbDataAdapter(command); DataTable dt = new DataTable(); sda.Fill(dt); sda.Dispose(); command.Dispose(); conn.Dispose(); 行抛出异常,sda.Fill(dt)只是作为字符串传递给函数的查询字符串。

2 个答案:

答案 0 :(得分:1)

add

SELECT m.playerID, b.RBI 
FROM [Master.csv] as m INNER JOIN
     [Batting.csv] as b
     ON m.playerID = b.playerID;

您可能需要更高级的语法来获取文件,但这会修复语法错误。

答案 1 :(得分:0)

第4行上的右圆括号(带有两个表名的圆括号)不应存在。如果您实际上想放置括号,则必须在ON子句之后,在JOIN语法(不是FROM语法)的固有部分中放置结束符:

SELECT 
    Master.playerID, Batting.RBI 
FROM 
    ([Master.csv] INNER JOIN [Batting.csv] 
ON 
    (Master.playerID=Batting.playerID))

或者,省略多余的括号:

SELECT 
    Master.playerID, Batting.RBI 
FROM 
    [Master.csv] INNER JOIN [Batting.csv] 
ON 
    Master.playerID=Batting.playerID

我将其格式设置为:

SELECT 
    Master.playerID, Batting.RBI 
FROM 
    [Master.csv]
    INNER JOIN [Batting.csv] ON Master.playerID=Batting.playerID