C # resuable library for processing a text file like a database table?

I would like to store the values ​​in a text file as values, separated by commas or tabs (this does not matter).

I am looking for a reusable library that can manipulate this data in this text file, as if it were a sql table.

I need select * from...and delete from where ID = ......(ID will be the first column in the text file).

Is there any plex code project that does this?

I don’t need complex functions like union or relationships. I will only have 1 text file, which will become 1 database table.

+3
source share
7 answers
+2
source

ODBC. Microsoft csv-Files. , . , ODBC, . linq.

+2

FileHelpers? CLR. - LINQ to Objects, .

+2
public class Item
{
    public int ID { get; set; }
    public string Type { get; set; }
    public string Instance { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        string[] lines = File.ReadAllLines("database.txt");

        var list = lines
                .Select(l =>
                    {
                        var split = l.Split(',');
                        return new Item
                        {
                            ID = int.Parse(split[0]),
                            Type = split[1],
                            Instance = split[2]
                        };
                    });

        Item secondItem = list.Where(item => item.ID == 2).Single();

        List<Item> newList = list.ToList<Item>();
        newList.RemoveAll(item => item.ID == 2);

        //override database.txt with new data from "newList"
    }
}

. LINQ , . List RemoveAll, , :

newList.RemoveAll(item = > item.ID == 2);

"LINQ to Text CSV Files": http://www.codeproject.com/KB/linq/Linq2CSV.aspx

+1

I would also suggest using ODBC. This should not complicate the deployment, the entire configuration can be installed in the connection string, so you do not need a DSN.

Along with the file, schema.iniyou can even set column names and data types; check the KB article from MS .

0
source

Source: https://habr.com/ru/post/1724708/


All Articles