读取固定格式文本文件
自从我不得不尝试使用 Microsoft Text ODBC Driver 或 Microsoft Jet OLE DB 4.0 Provider 读取文件以来,已经有很多年了。
所以我有以下代码
public void Example()
{
string CVS = Application.StartupPath;
string SQL = "SELECT * FROM [MyFile.txt]";
string Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+CVS+";"+"Extended Properties='text;HDR=Yes;FMT=Fixed;";
OleDbDataAdapter OLE = new OleDbDataAdapter(SQL,Connection);
DataTable Table = new DataTable();
OLE.Fill(Table);
}
当我运行上面的代码时,我收到“意外错误”,我知道我错过了一些东西,但我不确定到底是什么。
来源:
http://www.connectionstrings.com/textfile
http://www.connectionstrings.com/Providers/ net-framework-data-provider-for-ole-db
http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspx
任何方向将不胜感激。
让我们假设 Schema.ini 文件是正确的。
Its been years since I have had to attempt to read a file using either Microsoft Text ODBC Driver or Microsoft Jet OLE DB 4.0 Provider.
So I have the following code
public void Example()
{
string CVS = Application.StartupPath;
string SQL = "SELECT * FROM [MyFile.txt]";
string Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+CVS+";"+"Extended Properties='text;HDR=Yes;FMT=Fixed;";
OleDbDataAdapter OLE = new OleDbDataAdapter(SQL,Connection);
DataTable Table = new DataTable();
OLE.Fill(Table);
}
When I run the above code I get an "Unexpected Error", I know I am missing something, I am not sure what exactly.
Sources:
http://www.connectionstrings.com/textfile
http://www.connectionstrings.com/Providers/net-framework-data-provider-for-ole-db
http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspx
Any direction would be appreciated.
Let us assume the Schema.ini file is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从连接字符串中删除 '(位于 'text; 之前)。
为了解决“无法找到可安装的 ISAM”问题,请运行以下命令:
Regsvr32 c:\winnt\system32\mstext40.dll
* 首先确保该文件位于该文件夹中。并将 WINNT 更改为您的 Windows 目录。
Remove ' (just prior to 'text;) from the connection string.
In order to resolve the "Could not find installable ISAM", run the following command:
Regsvr32 c:\winnt\system32\mstext40.dll
* Make sure that file is in that folder first. And change WINNT to whatever your windows directory is.
我知道这不是您问题的真正答案,但我真的会重新考虑使用这种架构来读取文件。
我真的更喜欢像 CSV Reader 这样的东西,因为它给你关于如何解释数据的更多权力。或者,您也可以查看 FileHelpers。
I know this is not a real answer to your question, but i would really rethink about using this architecture to read in a file.
I would really prefer something like CSV Reader, cause it gives you much more power about how the data will be interpreted. Alternative you could also take a look into the FileHelpers.