Run SQL Queries on DataTables, or similar, in .Net, without an RDBMS
I'd like to have a dataset or datatables, and be able to run SQL statements on them, without using any external RDBMS.
For Example, to take take 2 datatables in a dataset and just join them outright with a SQL state开发者_JAVA技巧ment and Where clause, the result being a new datatable? For example if I have 2 datatables, named People and Addresses in a dataset (that I built using code, not getting from a database .. pardon the old fashioned Join syntax):
dim dtJoined as DataTable = MyDataSet.RunSQLQuery ("Select * from People, Orders Where People.PersonID=Orders.OrdereID")
Thanks
It is not sql, but if you want to query datasets and datatables your best bet is to use LINQ to DataSet
You're not going to be able to run SQL against it, because it isn't an RDBMS, but you can probably get what you want to accomplish using standard LINQ.
You could write it out to a temp csv file and read it using OLEDB
string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ fileDirectory + ";Extended Properties='text;HDR=YES;'";
OleDbDataAdapter oleda = new OleDbDataAdapter(sql, strCSVConnString);
DataTable dataTable = new DataTable();
oleda.Fill(dataTable);
In this case sql can be
SELECT * FROM fileName WHERE col = value
etc. We have had a fair amount of success with this.
精彩评论