与.csv文件连接时与OleDbException有关 [英] related to OleDbException when connet with .csv file
本文介绍了与.csv文件连接时与OleDbException有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想与.csv文件连接,但是会发生以下错误?
System.Data.OleDb.OleDbException:``E:\ cpjain \ testswcf \ excel \ 01061102.CSV''不是有效的路径.
我的代码正在关注
i want to connet with .csv file but the following error is occur ?
System.Data.OleDb.OleDbException: ''E:\cpjain\testswcf\excel\01061102.CSV'' is not a valid path.
my code is following
using ( OleDbConnection csvConnection = new OleDbConnection(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filename + ";Extended Properties=Text;")))
{
using ( OleDbCommand csvCommand = new OleDbCommand("SELECT * FROM 01061102.csv", csvConnection))
{
csvConnection.Open();
// Using a DataReader to process the data
using (OleDbDataReader reader = csvCommand.ExecuteReader())
{
while (reader.Read())
{
// Process the current reader entry...
}
}
// Using a DataTable to process the data
using (OleDbDataAdapter adp = new OleDbDataAdapter(csvCommand))
{
DataTable tbl = new DataTable("MyTable");
adp.Fill(tbl);
foreach (DataRow row in tbl.Rows)
{
// Process the current row...
}
}
}
}
[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
推荐答案
尝试这种方式:)
try this way :)
using System.IO;
if(File.Exist(filename))
{
///put your code here
}
else
{
//invalid file path
}
检查文件是否存在以及您是否具有访问权限.如果它是网络路径或USB驱动器(看起来很可能),请检查它是否可访问并正确插入.
Check that the file exists, and that you have access permissions. If it is a network path or USB drive (as looks likely) check it is accessible and plugged in correctly.
这篇关于与.csv文件连接时与OleDbException有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文