views:

105

answers:

2

Hi,

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 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.

+3  A: 

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"]);
Konstantin Spirin
Andreas
+1  A: 

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.

Konstantin Spirin
Yes, I was thinking about that. But up to now I haven't found a way to use it with VS 2005.
Andreas
Google for `LinqBridge` if you want to have linq in .Net 2.0. But you better use VS2008 targeting 2.0 rather than VS2005, otherwise extension methods and lambda won't work and code will have to be ugly
Konstantin Spirin