'Using files as SQL tables

I have CSV files which basically are tables from SQL database. They have following content:

ColumnName1,name2,name3

Value1,value2,value3

Value1,value2,value3

File naming is following: tablename (no extension)

I have 10 such tables. How is it possible to merge such files? Is it maybe possible to somehow use SQL commands such as join, where, or, and.. Etc..?

I can load them separately into arrays using the hardcode. I can use if, else statements to hardcode joins and wheres. What I am asking here - is an advice how to operate such tables in an easier way.

My main goal is to merge tables and filter the result. Result will probably be displayed in datagridview.

I am planning on using this tool at work, so only free of charge (free license, open source) libraries or tools are currently sought.



Solution 1:[1]

If I understand correctly, you have 10 "tables" with the same schema, since you want to merge them. In that case I'd create a struct like

public struct Line {
    int Column1;
    string Column2;
    float Column3;
}

Then I'd populate a List with the content of the file(s). You can then use LINQ (which is similar to SQL) very easily on this data structure. Here is a good walkthrough for using queries on lists of structs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 selator