"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();} }}
这就是我正在尝试的