我正在使用此函数从csv文件中获取数据集:
public static DataSet GetDataset(string filePathName, string fileName, string fieldNames)
{
OleDbConnection CSVConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePathName + ";Extended Properties='text;HDR=Yes;FMT=Delimited(,)';");
OleDbCommand CSVCommand = new OleDbCommand(@"SELECT " + fieldNames + " FROM [" + fileName + "]", CSVConnection);
OleDbDataAdapter CSVAdapter = new OleDbDataAdapter(CSVCommand);
DataSet CSVDataSet = new DataSet();
try
{
CSVConnection.Open();
CSVAdapter.Fill(CSVDataSet);
return CSVDataSet;
}
catch(Exception ex)
{
return CSVDataSet;
}
finally
{
CSVConnection.Close();
CSVConnection.Dispose();
}
}
但是,在使用oledb提供程序
读取csv文件时,我在服务器上遇到以下错误消息:未指定错误 StackTrace:在System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString) constr,OleDbConnection连接)at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options,Object poolGroupProviderInfo,DbConnectionPool池, DbConnection owningObject)at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(的DbConnection owningConnection,DbConnectionPoolGroup poolGroup)at System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection 拥有连接) System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory)at DB.GetDataset的System.Data.OleDb.OleDbConnection.Open()(String filePathName,String fileName,String fieldNames)