0

i have the SQL Query in a string and am executing using the Traditional way of using DataAdapter.

Am trying to add pagination to the Existing logic. how do i add Skip take to the SQL string.

I know of using Skip and other linq methods for LINQ Queries. But is it possible to use for a SQL query in a string format.

If yes how do i do it without adding RowNum to the query rather use skip and take.

Eg :

String sqlQuery = Select * from tablename ;
SqlDataAdapter com = new SqlDataAdapter(sqlQuery, Connection);

How do i use Linq methods on this SQL query for pagination rather going for ROWNUM

*Am not sure if am repeating the Question but i was not able to identify with the keywords

Thanks

user2067567
  • 3,695
  • 15
  • 49
  • 77

1 Answers1

3

How do i use Linq methods on this SQL query for pagination rather going for ROWNUM

You can't. You're issuing direct SQL - LINQ isn't involved here. LINQ will translate a query written in C# into SQL, but you can't start adding bits of LINQ to an existing SQL query. You should decide whether you actually want to write SQL, or whether you want to use LINQ. Then do just one at a time.

(You can use both in the same project, sure - but for a single query, you can't mix and match.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks @jon am dynamically forming the SQL query so i would go with ROWNUM.Any best approach for implementing with rownum you can redirect to would be great ! – user2067567 Jul 02 '13 at 12:25
  • @user2067567: That sounds like you should be asking a different question - at that point you're really only asking about SQL, with nothing to do with C# or LINQ. – Jon Skeet Jul 02 '13 at 12:26
  • Agree @jon !! ll see if i can find any :) Thanks +1 solution – user2067567 Jul 02 '13 at 12:28