寻找从CSV文件中检索数据的最佳/最快方法 [英] Looking for the best/fastest way to retrieve data from a CSV file

查看:858
本文介绍了寻找从CSV文件中检索数据的最佳/最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编程好几年了,但直到现在,我从来没有需要访问数据,所以这对我来说都是新的。我需要从CSV文件中读取数据。如果重要,则包含大约7000行的文件。似乎有几种方法可以做到这一点。 

I've been programming for several years, but until now, I've never needed to access, data so it's all very new to me. I need to read data from a CSV file. A file that contains about 7000 lines if that's important. There seems to be several ways to do this. 

1。我可以使用 FileHelpers 并迭代< List>中的每一行。但这似乎很慢,因为我需要做很多次。 

1. I can use FileHelpers and iterate over each line in a <List>. But this seems slow as I'll need to do this A LOT of times. 

2。 Co-Worker建议我使用ODBC并对文件运行查询。不是问题,但我不知道该怎么做。

2. A Co-Worker suggested I use ODBC and run a query on the file. Not a problem, but i have no idea how to do that.

3。使用LINQ。我只玩了一点LINQ。 

3. Use LINQ. I've only played with LINQ a little. 

4。它们的组合......

4. A combination of them...

5。还有一些我还没有听说过的......

5. Something else I haven't heard of yet...

这是我的问题。我意识到我需要做一些研究。但是因为我会做很多"查询"。在这个计划中,速度是我最关心的问题。例如,我希望能够"从此文件中选择此项和那项,此
列具有此数据" (伪代码显然)。我想学习最快的方法。谁能告诉我最佳方向呢?

Here's my question. I realize i need to do some research. But because I will be doing a lot of "querying" in this program, speed is my biggest concern. For example, I would like to be able to "select this and that from this file, where this column has this data" (pseudo code obviously). I would like to learn the fastest method. Can anyone tell me the best direction to take?

我希望我已经提供了足够的信息。如果没有让我知道。 

I hope I've provided enough info. If not let me know. 

谢谢。 

推荐答案

对你和计算机来说最容易使用String.Split如果它适合你。如果任何字段都使用逗号作为数据的一部分并且这是一种确定的可能性,那么它将无法轻松工作。如果您需要处理的文件没有
该功能,请尝试  String.Split。您可以通过阅读每条记录并执行  String.Split进行快速测试,然后如果任何记录拆分成包含多于预期的项目的数组,那么您就知道
是使 
String.Split无用的记录。
The easiest for you and the computer is probably to use String.Split if it will work for you. It would not work easily if any of the fields have commas as part of the data and that is a definite possibility. If the file(s) you need to process don't have that feature then try String.Split. You can do a quickie test by just reading every record and doing a String.Split and then if any record splits into an array with more items than expected then you know there are records that make String.Split not useful.


这篇关于寻找从CSV文件中检索数据的最佳/最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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