不知道错在哪啦,请帮忙看看
如下代码:
using System;
using System.Data.OleDb;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
OleDbConnection myConn =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\MyExcel.csv;Extended Properties='text;HDR=YES;FMT=TabDelimited'");
Console.WriteLine(myConn);
myConn.Open();
}
}
}
MyExcel.csv的位置截图
MyExcel.csv的内容截图
运行出错截图
未处理
System.Data.OleDb.OleDbException
_HResult=-2147467259
_message='c:\MyExcel.csv'不是一个有效的路径。 确定路径名称拼写是否正确,以及是否连接到文件存放的服务器。
HResult=-2147467259
IsTransient=false
Message='c:\MyExcel.csv'不是一个有效的路径。 确定路径名称拼写是否正确,以及是否连接到文件存放的服务器。
Source=Microsoft JET Database Engine
ErrorCode=-2147467259
StackTrace:
在 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
在 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
在 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnect