Creating a Queried DataTable From an Existing DataTable

L

Lee Ottaway

I am manually creating a datatable in memory, creating columns etc for
it and then populating it by importing data from files and various
databases. Once I have the datatable in memory (which consists of
around 10000 records) I need to be able to perform queries on it. I'm
not talking about merely filtering or sorting it which I could do with
a DataView, but performing real queries on it like grouping and
counting.

I can obviously do this by saving the datatable to a database and then
using the OleDbDataAdapter to perform these kind of queries, but I
don't want to have to save the data to a database, firstly because I
don't need to store it and secondly because its incredibly slow saving
10000 records across a network.

Is there a way I can perform SQL queries on a datatable that exists
only in memory?

Thanks


Lee
 
M

Miha Markic [MVP C#]

Hi Lee,

Lee Ottaway said:
I am manually creating a datatable in memory, creating columns etc for
it and then populating it by importing data from files and various
databases. Once I have the datatable in memory (which consists of
around 10000 records) I need to be able to perform queries on it. I'm
not talking about merely filtering or sorting it which I could do with
a DataView, but performing real queries on it like grouping and
counting.

I can obviously do this by saving the datatable to a database and then
using the OleDbDataAdapter to perform these kind of queries, but I
don't want to have to save the data to a database, firstly because I
don't need to store it and secondly because its incredibly slow saving
10000 records across a network.

Is there a way I can perform SQL queries on a datatable that exists
only in memory?

No, there isn't.
You might perform foreach loops (in combination with RowFilter perhaps)
though and check/calculate there.
You might also use DataTable.Select method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top