开发者

.net 2.0: What's the best way to deal with in-memory DataTables?

I have a csv file that I import into a DataTable. Furthermore I've created a TableAdapter with several queries. Is it somehow possible to execute the queries associated with the TableAdapter directly on the "in-memory" DataTable (doesn't seem so) or do I always have to write the imported DataTable to the database first and then execute the TableAdapter queries on the persisted data? I wanted to use the datatable开发者_如何学Go directly as it is a small project and it's not worth converting the data back and forth from value object to datatable or use OR mappers.

Thanks in advance!

Best regards,

Andreas

PS: It is only a small amount of data, so the memory impact should not be that big.


You can use Select method of DataTable. It takes SQL-like filter (similar to what you write in where clause)

var table = new DataTable();

table.Columns.Add("Value");

table.Rows.Add(1);
table.Rows.Add("One");

var rows = table.Select("value='One'");

foreach (var value in rows)
    Console.WriteLine(value["Value"]);


Load whole file into memory and use Linq to DataSet.

The same queries could transparently work with SQL database (Linq to SQL) but I don't know if there's something like Linq to CSV or Linq to ODBC.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜