Reputation: 169
I have data in excel and I have transformed it into a datatable so that I can use it to query with sql statements. But querying datatable in c-sharp is not straightforward. Can anyone suggest a way to temporary read data from excel file hold it in memory, ask some queries hold results in datagridview and delete data from memory.
Upvotes: 0
Views: 129
Reputation: 120
You can query against the rows in a DataTable by using Linq.
This can be found using a Google search for examples.
What is Linq?
Linq was/is developed by Microsoft as a programming model that gives you the ability to perform queries within the .net. Linq can also be used on multiple sources, such as DataTables, SQL Databases, arrays and more. The great thing about Linq is that it uses SQL-like syntax to make it understandable for Database Developers and Software Developers. However, do note that it is not as powerful as SQL due to only supporting less advanced techniques, however you can find out more about this when researching.
Linq Example
This example of Linq queries an array called words where the word length is = 3 and returns them.
from word in words where word.length == 3 select word;
Upvotes: 1