1
"INSERT INTO CricketMatch
(FName,LastName,Runs,Matches,Location,DateofMatch,PLayerId)
SELECT
    Fname,Lname,Runsby,numberofMatches,MatchLocation,DofMatch,Id
FROM [Text;Data Source=C:\\DB\\;HDR=YES].[filename]";

文件名只是扩展名为 demo.csv 的名称,没有路径

cmd.CDataSet da = new DataSet();string filename = Path.GetFileName(txtCSVFilePath.Text);
try {da = this.ConnectCSV(filename);
     string connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\DB\\MatchDetails.accdb"; 
    OleDbConnection conn = new OleDbConnection(connstring);
    OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;conn.Open(); 
    for (int i = 0; i <= da.Tables["Ss"].Rows.Count - 1; i++){ 
        for (int j = 1; j <= da.Tables["Ss"].Columns.Count - 1;j++){ 
           cmd.CommandText="INSERTINTOCricketMatch(FName,LastName,Runs,Matches,Location,DateofMatch,PLayerId)SELECT(Fname,Lname,Runsby,numberofMatches,MatchLocation,DofMatch,Id)  FROM [Text;FMT=Delimited(;);HDR=NO;DATABASE=C:\\DB]." + filename;cmd.Connection = conn; cmd.ExecuteNonQuery();} }} 

这就是我正在尝试的

4

2 回答 2

4

您的语法看起来非常接近 - 尝试这样的连接到 csv 文件:

SELECT Fname,
  Lname,
  Runsby,
  numberofMatches,
  MatchLocation,
  DofMatch,
  Id 
FROM [Text;FMT=Delimited;HDR=YES;DATABASE=C:\DB].filename.csv;
于 2013-01-10T19:15:59.143 回答
1

就像这样,正如我已经说过的:

INSERT INTO CricketMatch
(FName,LastName,Runs,Matches,Location,DateofMatch,PLayerId)
SELECT
    Fname,Lname,Runsby,numberofMatches,MatchLocation,DofMatch,Id
FROM [Text;Database=z:\docs\;HDR=yes].[importfilename.csv]
于 2013-01-10T19:59:08.190 回答