Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

How to Load a Flat Text File Into a Table in C# and Use LINQ in Order to Query for Data Fields

I have a flat file that I am reading data from and I am currently reading the data into an ArrayList. I will need to update the application to be able to read in more than one data file, and I was wondering if someone could explain to me how I would read the data in from a *.dat file and use LINQ in order to get the specific fields from the data table that would be created from reading in the information from the flat file. (I do have business rules that split the flat data table into different fields, and I would like to be able to store these fields within a temporary table in memory so that I could query them and be able to pull back results based on the information a user enters. Could someone direct me to example code that completes this task or if they could help me with the syntax that I would need in order to accomplish this task?

Any help with this task would be greatly appreciated.
0
thenthorn1010
Asked:
thenthorn1010
1 Solution
 
käµfm³d 👽Commented:
For Linq-to-DataTable, you can generally do something like:

var query = from row in dt.Rows.OfType<DataRow>()
            where row.Field<string>(0) == "some value"
            select row;

foreach (var item in query)
{
    Console.WriteLine(item.Field<string>(0));
}

Open in new window


This is a very crude example, and you would have to change it to fit your scenario, but hopefully it demonstrates the concept. You can also select into a new existing or anonymous type if you don't want to return DataRows.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now