读取文本文件内容并从数据库获取数据. [英] read text file content and get the data from database.

查看:108
本文介绍了读取文本文件内容并从数据库获取数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须读取一个包含companyIds(大约75000)的文本文件.读取文本文件内容后,我需要从数据库中获取相应的公司信息并写入输出文本文件(YYYYMMDDhhmmss_out.txt)中.文本文件并将公司ID加载到集合对象(LIST< t>)中.但是如何一次将公司信息全部写入单个输出文件中.我试图将第一家公司信息写入输出文件中,但是当我尝试将再次写入下一个公司信息正在创建新的输出文件(文件名在mmsss部分中有所不同),因为它不应该这样.如何一次将公司信息全部写入一个输出文件.

谁能帮我注册一下.

在此先感谢.

Hi,

I have to read a text file which contains companyIds(approximately 75000).After reading the text file content, i need to get the corresponding company information from the database and write to a output text file(YYYYMMDDhhmmss_out.txt).I tried to read the text file and loaded the companyids into a collection object(LIST<t>).But how to write the company information all at a time into single output file.I tried to write first company info to output file,but when i tried to write the next company info again new output file is getting created (with file name differs in mmsss part) as it should not be.How to write the company information all at a time to a single output file.

Can anyone please help me reg this.

Thanks in Advance.

推荐答案

使用datarow读取数据库内容,使用streamwriter写入文件.
对多个记录使用foreach循环,请确保将此行置于循环之外
use datarow to read database content, use streamwriter to write into file.
use foreach loop for multiple records make sure that you keep this line out of the loop
StreamWriter writer=new StreamWriter(@"filepath")


这篇关于读取文本文件内容并从数据库获取数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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