上载文本文件,阅读它们,然后将其插入数据库. [英] Uploading text files, reading them, and inserting into a database.

查看:89
本文介绍了上载文本文件,阅读它们,然后将其插入数据库.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个任务,我必须上传一个.txt文件,然后从该文件中读取并将数据插入数据库表中.该文件没有定界符,而是具有设置的长度(例如,一个字段的长度为20个字符,另一个字段的长度为2个字符).
我没有太多的经验来上传/处理这样的文件,因此任何建议都是不错的选择. :)

在此先感谢您.

Hi everyone,
I have a task where I have to upload a .txt file and then read from the file and insert the data into a database table. The file doesn''t have delimiters, instead it has set lengths (eg. one field is 20 chars long, another is 2 chars long).
I don''t have too much experience uploading/manipulating files like this, so any advice would be great. :)

Thanks in advance.

推荐答案

如果您没有执行此任务的经验,为什么要给予它?总是让我不高兴的部分是,在大多数情况下,这意味着没有技能的人会得到报酬去做应该交给有经验的程序员的工作.

如果它们是固定大小,则更加容易. File.ReadAllLines会将您的文件读入字符串数组.字符串类的Substring方法可让您将字符串分成多个部分.然后,您只需将这些变量放入数据库中即可.
Why have you been given this task if you have no experience in doing it ? The part that always upsets me, is that most of the time, this means someone with no skills is being paid to do a job that should go to an experienced programmer.

If they are fixed size, then it''s even easier. File.ReadAllLines will read your file into an array of strings. The Substring method of the string class will let you chop up your string into sections. Then you just take those variables and put them in the database.


查看 SQL区域 [ ^ ]以获得一些入门文章.
Check out the SQL Zone[^] for some starter articles.


您好,

我个人认为,Christian建议的方法绝对适用于没有大量记录或您不太在意性能的文件.

由于您是学生,如果有时间,我建议您考虑将数据批量插入数据库中.

例如,如果您的数据库后端是SQL Server,请查看SMO(2005/08)或DMO(2000)


问候
Hi there,

In my personal opinion, the method that Christian suggested is absolutely fine for files which do not have a large number of records or you do not care much about performance.

Since you are a student, if you have time, I would suggest looking into bulk inserting data into database.

For example , if your database backend is SQL Server , have a look at SMO (2005/08) or DMO (2000)


Regards


这篇关于上载文本文件,阅读它们,然后将其插入数据库.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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