开发者

C# .NET - Datatype to map CSV file data

In one of my ASP.NET applications in C#, Suppose I n开发者_如何转开发eed to read CSV file (and do some stuff of course) and in some other function I need to read another csv file and do some other stuff with the data. PS: We are using oledb to read CSV file.

My question is will it be good to have a common function like readCSV(fileName) to read csv file or we should write all oledb commands (i.e. oledbconnection, open, close etc) in every function differently.

  • Problem with the option one is we need to loop through twice (i.e. 10K times to read from csv and 10K times to validate) - (By the way what will be the best data type that readCSV should return? if your suggestion is option one).

  • Problem with the option two is that we need to write all oledb commands (i.e. oledbconnection, open, close etc) in every function that we implement to do different tasks with CSV data.


I'd put all your DB code into a service layer and call that to parse your csv files. This way, if your source ever changes, you only have a small chunk of code to edit.

You could either create objects for each of your csv files or use dynamic objects. Your service layer would then return either IEnumerable or IQueryable.


Have you looked at Generic Parser?

http://www.codeproject.com/KB/database/GenericParser.aspx

It seems to be used fairly widely, reads CSV files fast and is likely flexible enough for your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜