如何在不评估数据类型的情况下一般读取文本文件并保存到数据库中?
我需要编写一个 C# 程序来读取任何平面文本文件,并且对于每一行,使用先前保存在配置文件中的 regex 表达式进行解析,该表达式将行分隔在存储在一个配置文件中的多个字段中。 List
对象,其中每个元素都是一个字段。然后,将每个字段保存在先前在数据库表中创建的相应字段中,依此类推。
此时,一切都被视为数据是在不受干扰的情况下编排的,就像从文本文件到数据库的管道一样。然而,我面临的困难是,某些字段可以以不同的格式(bool、double 等)表示日期/小时。对于这几种情况,我需要修改我的程序并制作某种 if 语句 会最小化处理时间的开销。
问题是知道 C# 中是否有任何方法或技术,尽管提到了特殊情况,但它允许我将数据记录在数据库中,而无需以前评估来建立数据类型的开销?
谢谢。
I need to write a C# program for reading any flat text files and, for every line, parses using a regex expression previously saved in a configuration file, which separates the line in several fields that are stored in a List
object where each element is a field. Then, let each field be saved in the respective fields previously created within a database table and so on for each line.
At this point, everything is seen as that data is orchestrated without interference, as a pipe that runs from the text file to the database. However, I face the difficulty where some of the fields can represent dates/hours in different formats, bool, double etc. For these few cases, I will need to modify my program and make some sort of if-statements
that would minimally generate an overhead in processing times.
The question is to know whether there is any methodology or technique within the C# that, despite the special cases mentioned, it allows me to record the data in the database without the overhead of previous evaluations to establish the data type?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不将文本文件中的所有数据写入字段均为字符串(varchar、text 等)的数据库中。在某些时候,您必须需要查询数据库才能使用这些值,此时您可以将字符串转换为各自的数据类型。
Why not just write all of the data from the text file into a database whose fields are all strings (varchar, text, etc). At some point you must need to query the database to use the values, and that's when you can convert from the strings into their respective data types.