将txt文件读取到DataSet [英] Read txt File to a DataSet

查看:88
本文介绍了将txt文件读取到DataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我可以将.TXT文件读取到DataSet吗?我怎么能这样做?

我想把他的行读到DropDownList。这行是我从我的应用程序导出的

员工的名字。

我将它们导出到.txt文件,我想工作。这个员工在我的

aspx页面中。你能帮助我吗?

这有点奇怪,但这就是我需要的。 :)

-


感谢'(如果你试图帮助我)

希望这对你有所帮助(如果我试着帮助你)

ruca

Hi,

Can I read a .TXT File to a DataSet? How can I do that?
I want to read his lines to a DropDownList. This lines are the names of
employees that I export from an application that I have.
I export them to a .txt file and I want to "work" with this employees in my
aspx page. Can you help me?
It''s a little bit strange, but it''s what I need. :)
--

Thank''s (if you try to help me)
Hope this help you (if I try to help you)
ruca

推荐答案

你能否将文本文件更改为xml?数据集可以很容易地吸收这个数据,因为它内置了对此的支持。否则,你将需要解析文件的内容并创建新行,将

内容添加到这些行中。它不会那么漂亮,但这些是你有的选择。


-

此致,

Alvin Bruney [ASP.NET MVP]

得到花絮?在此处获取...
http://tinyurl.com/3he3b

" ruca" < RU *** @ iol.pt>在消息中写道

news:eF **************** @ tk2msftngp13.phx.gbl ...
Can you possibly change the textfile to xml? The data set can suck this up
pretty easily because it has built in support for this. Otherwise, you will
need to parse the contents of the file and create new rows adding the
contents to these rows. It''s not going to be pretty this way but these are
the options that you have.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"ruca" <ru***@iol.pt> wrote in message
news:eF****************@tk2msftngp13.phx.gbl...


我可以将.TXT文件读取到DataSet吗?我怎么能这样做?
我想把他的行读到DropDownList。这行是我从我的应用程序导出的
员工的名字。
我将它们导出到.txt文件,我想工作。这个员工在
我的aspx页面。你能帮助我吗?
这有点奇怪,但这就是我的需要。 :)

-

感谢'(如果你试图帮助我)
希望这对你有帮助(如果我试着帮助你的话)
ruca
Hi,

Can I read a .TXT File to a DataSet? How can I do that?
I want to read his lines to a DropDownList. This lines are the names of
employees that I export from an application that I have.
I export them to a .txt file and I want to "work" with this employees in my aspx page. Can you help me?
It''s a little bit strange, but it''s what I need. :)
--

Thank''s (if you try to help me)
Hope this help you (if I try to help you)
ruca



是的,你可以。


文本文件是否以逗号分隔?如果是,你可以像使用数据库表一样使用.net OleDBObject读取文件


如果它不是逗号分隔文件,即使它是你可以使用.NET StreamReader对象并手动构建可添加到数据集的数据表


StreamReader对象示例
http://samples.gotdotnet.com/quickst...c/Anagrams.asp


读取文本文件并从中生成数据集涉及一些开销。除非您计划将数据集用于其他事情,而不仅仅是绑定到下拉列表,我认为将项目添加到下拉列表中作为读取/解析文本文件是有效的


如果您需要重复使用此下拉列表,您可以随时缓存控件


HTH

Suresh


- ---- ruca写道:----


您好


我可以将.TXT文件读取到DataSet吗?我怎么能这样做

我想把他的行读到DropDownList。这行是名称o

员工,我从我有的应用程序导出

我将它们导出到.txt文件,我想工作这个员工在m

aspx页面。你能帮我吗

这有点奇怪,但这就是我的需要。 :

-


感谢'(如果你试图帮助我)

希望这对你有帮助(如果我尝试帮助你

ruc

Yes you can.

Is the text file comma delimited? If yes, you can use the .net OleDBObject to read the file as you would a database table

If it isn''t a comma delimeted file and even if it is you can use the .NET StreamReader object and manually build a datatable that you can add to a dataset

Example of StreamReader object
http://samples.gotdotnet.com/quickst...c/Anagrams.asp

Reading a text file and generating a dataset out of it involves some overhead. Unless you plan to use the dataset for other things than just to bind to a dropdownlist I think it would be efficient to add the items to your dropdownlist as your reading/parsing the text file

If you have a need to reuse this dropdownlist you can always cache the control

HTH
Suresh

----- ruca wrote: ----

Hi

Can I read a .TXT File to a DataSet? How can I do that
I want to read his lines to a DropDownList. This lines are the names o
employees that I export from an application that I have
I export them to a .txt file and I want to "work" with this employees in m
aspx page. Can you help me
It''s a little bit strange, but it''s what I need. :
-

Thank''s (if you try to help me
Hope this help you (if I try to help you
ruc


>我可以将.TXT文件读取到DataSet吗?我该怎么办?


您可以通过编程方式选择文本文件并将其添加到

数据集中,是的。但是DataSet类中没有类似的方法,

ReadTextFile()。
> Can I read a .TXT File to a DataSet? How can I do that?

You could programmatically pick through the text file and add it to the
DataSet, yes. But there''s not a method in the DataSet class like,
ReadTextFile().
我想把他的行读到DropDownList。
I want to read his lines to a DropDownList.




也许更简单的方法是以编程方式逐步执行代码行并将其添加到DropDownList的Items集合中。

类似于:


StreamReader sr = File.OpenText(filepath);

while(sr.Peek()> = 0)

myDDL.Items。添加(新的ListItem(sr.ReadLine());

sr.Close();

类似的东西应该做的。

Happy Progra mming!


-


Scott Mitchell
mi ****** @ 4guysfromrolla.com
http ://www.4GuysFromRolla.com
http://www.ASPFAQs。 com
http://www.ASPMessageboard.com


*当你想到ASP时,请考虑4GuysFromRolla.com!




Perhaps an easier approach would be to just programmatically step through
the lines of code and add it to the DropDownList''s Items collection.
Something like:

StreamReader sr = File.OpenText(filepath);
while (sr.Peek() >= 0)
myDDL.Items.Add(new ListItem(sr.ReadLine());
sr.Close();
Something like that ought to do the trick.

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!



这篇关于将txt文件读取到DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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