固定长度记录并创建文件

发布于 2024-12-26 16:13:23 字数 170 浏览 4 评论 0原文

我必须使用 C# 创建一个固定长度的记录文件。我从数据库中读取记录,然后在一些业务逻辑之后,我想将一些字段写入文本文件。 我对此进行了研究,有些人建议使用 XML 来定义文件,而其他人则格式化字符串,然后将其写入文件中。

有没有正确的方法来做到这一点?我想保持这个面向对象。

感谢您的任何提示。

I have to create a fix length record file using C#. I read the records from database and then after some business logic I would like to write some of the fields into a text file.
I researched this and some recommend using an XML to define the file, while others format the string and then write that into a file.

Is there a proper way to do this? I would like to keep this object oriented.

Thanks for any hints.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

金兰素衣 2025-01-02 16:13:23

take a look at http://www.filehelpers.com/ to export the data to a fixed file format. you may also want to look at http://hibernatingrhinos.com/open-source/rhino-etl to create a process that runs the export for you. rhino.etl includes operations for FileHelpers.

挽心 2025-01-02 16:13:23

您可以使用 Jet 解析文本文件中的固定长度记录。这是一个不错的概述,应该能够帮助您入门:

http://msmvps.com/blogs/deborahk/archive/2009/08/25/reading-fixed-length-files.aspx

You can use Jet to parse fixed length records in a text file. This is a decent overview that should be able to get you started:

http://msmvps.com/blogs/deborahk/archive/2009/08/25/reading-fixed-length-files.aspx

撩心不撩汉 2025-01-02 16:13:23

过去,当我这样做时,我将数据作为 Char(Length) 从 SQL 中取出,以便由 SQL 处理填充。这使得 C# 非常容易组合在一起。您可以通过在选择数据时转换或转换数据来实现此目的,或者创建一个与文件格式完全相同的表并在其中插入数据,然后将其拉出到 C# 中。

In the past when i've done this, I pull the data out of SQL as a Char(Length) so that the padding is handled by SQL. This makes the C# pretty easy to put together. You can do this by casting or converting the data when you select it, or by creating a table that is the exact format of your file and inserting the data in there before pulling it out into C#.

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