0

Is there's way to execute SQL queries directly on dataset or datatable . Query which need to be executed is much complex and it may be difficult to implement with Linq .

Is there any similar way to query directly from dataset or datatable ?

Is there any tools available to convert complex queries to linq ?

Midhun Murali
  • 2,089
  • 6
  • 28
  • 49
  • Your second question: Try Linqer: http://www.sqltolinq.com/ – Marco Jun 26 '14 at 13:54
  • As to your first question: In your link, the northwind database is queried, but your topic states dataset? Are we talking about linq-to-sql or linq-to-dataset ? – Marco Jun 26 '14 at 13:57
  • @Serv corrected the question , i am talking about querying from Dataset or DataTable not from DB. – Midhun Murali Jun 26 '14 at 13:59
  • SQL queries are not processed by .NET - they are processed by a SQL engine like SQL Server. You could spin up a low-overhead SQL instance like [**LocalDB**](http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx), dump the data in there, and then query against it. – mellamokb Jun 26 '14 at 14:00
  • If you have the data in a dataset, you have already processed the data and fetched it from the database. So: why do you want to query the dataset instead of improving the query to the database? – Marco Jun 26 '14 at 14:08
  • Why in this world would you need to execute a complex query in ADO.net? DB engine is best suited for that. Do it in Stored proc and get the ready-to-use data to the client. – T.S. Jun 26 '14 at 15:31

2 Answers2

0

There is a DataTable.Select() method, which returns rows that match certain criteria.

The syntax is a little limited, however. Example:

DataTable.Select("Date > #1/1/2014# AND Name = \"John\"");

Should select any rows where the Date column has a date value that's 1/1/2014 or later, and the Name column is "John". Also handy is using String.Format() with it.

DataTable.Select(String.Format("Date > {0} AND Name = {1}", date, name));

This is severely limited compared to fixing it in the actual query, though.

0

try to use tools like LinqPad or some thing similiar
Download LinqPad
also one other way is to create your complex queries in database as VIEW and then write a simple select from VIEW!
another approach is, using MethodChain
What is the correct way to chain methods in .Net

Community
  • 1
  • 1
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62