读成CSV使用OLEDB [英] Reading CSV into using OLEDB

查看:287
本文介绍了读成CSV使用OLEDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误找不到可安装ISAM
,当我尝试使用OLEDB连接字符串来读取csv文件。



请协助



我的代码是:

 如果(文件.Exists(openFileDialog1。文件名))
{
的ConnectionString =的String.Format(供应商= Microsoft.Jet.OLEDB.4.0;数据源=+ openFileDialog1.FileName +;扩展属性=文本; HDR =是; FMT =分隔符号);
CON =新的OleDbConnection(的ConnectionString);
查询字符串=SELECT * FROM [工作表Sheet1 $];
Con.Open();
= DataAdapter的新OleDbDataAdapter的(查询,CON);
DT =新的DataTable();
DataAdapter.Fill方法(DT);

dataGridView1.DataSource = DT;
}


解决方案

这个错误也将时产生的连接字符串的语法不正确。 - MSDN



当我试图复制你的ConnectionString,似乎很喜欢有很多的空间在里面。

 的ConnectionString =的String.Format(供应商= Microsoft.Jet.OLEDB.4.0;数据源=+ openFileDialog1.FileName +;扩展属性=文本; HDR =是; FMT =分隔符号); 

如果这似乎并没有解决您的问题,我建议你看一看的这个


I'm getting the error "Could not find installable ISAM" when I try to read csv file using OLEDB connection string.

Please assist

My code is:

       if (File .Exists(openFileDialog1 .FileName ))
       {
        ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data          Source="+openFileDialog1.FileName +";Extended Properties=text;HDR=Yes;FMT=Delimited");
        Con = new OleDbConnection(ConnectionString);
        string query = "Select * From [Sheet1$]";
        Con.Open();
        DataAdapter = new OleDbDataAdapter(query, Con);
        dt = new DataTable(); 
        DataAdapter.Fill(dt);

        dataGridView1.DataSource = dt;
       }

解决方案

"This error will also be generated when the syntax of the connection string is incorrect." - msdn

When i tried to copy your connectionstring, it seemed liked there were alot of spaces in there.

 ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+openFileDialog1.FileName +";Extended Properties=text;HDR=Yes;FMT=Delimited");

if this does not seem to resolve your issue, i suggest you take a look at this

这篇关于读成CSV使用OLEDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆