读取固定格式文本文件

发布于 2024-12-29 09:04:24 字数 1121 浏览 4 评论 0原文

自从我不得不尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情丝乱 2025-01-05 09:04:24

从连接字符串中删除 '(位于 '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.

夜吻♂芭芘 2025-01-05 09:04:24

我知道这不是您问题的真正答案,但我真的会重新考虑使用这种架构来读取文件。

我真的更喜欢像 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文