我正在使用以下两个代码读取 csv 文件,但它返回相同的错误。
'E:\business\business\Document\4112013\20580.csv' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
我无法解决这个问题。请帮我解决这个问题
SaveLocation = @"E:\business\business\Document\4112013\20580.csv";
string connStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=@" + SaveLocation + ";Extended Properties=\"Text;HDR=YES;FMT=Delimited\"";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
// give full path to the file here
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + SaveLocation, conn);
DataSet ds = new DataSet("QueryCSV");
adapter.Fill(ds);
DataTable dt = ds.Tables[0];
System.Data.OleDb.OleDbDataAdapter MyCommand = default(System.Data.OleDb.OleDbDataAdapter);
System.Data.OleDb.OleDbConnection MyConnection = default(System.Data.OleDb.OleDbConnection);
//MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; " + "data source=" + SaveLocation + "; " + "Extended Properties=Excel 12.0;");
//MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; " + "data source=" + SaveLocation + "; " + "Extended Properties='csv;HDR=Yes;FMT=Delimited(,)';");
MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + SaveLocation + ";Extended Properties=\"Text;HDR=YES;FMT=Delimited\"");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet5$]", MyConnection);
ds = new System.Data.DataSet();
MyCommand.Fill(ds);