0

I try to run this:

SqlDataAdapter da = new SqlDataAdapter("Select top 100 * from table_name order by id desc", conn)

and I am getting all the rows back instead of the last 100.

5
  • Remove TOP 100 from your select statement. Commented Feb 26, 2014 at 21:39
  • Not clear the problem, do you want only 100 rows and this query returns all rows or do you want all rows and this query returns only the last 100? Commented Feb 26, 2014 at 21:43
  • I want the last 100 rows in the table Commented Feb 26, 2014 at 21:45
  • That query should works. Perhaps there is other code that changes the command. Could you add the code that execute the adapter? Commented Feb 26, 2014 at 21:46
  • 2
    Put a trace/sql profiler on it..see what is getting sent to the database. Commented Feb 26, 2014 at 21:59

2 Answers 2

1

Try running the SQL profiler and check what is the actual query that is being executed in the database.

That should give you more idea about how to proceed.

Sign up to request clarification or add additional context in comments.

Comments

0

You have TOP 100 in your SELECT statement thats why it only returns 100 rows. remove TOP 100 fromy your select and it will return all the rows.

SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM table_name ORDER BY id DESC", conn)

3 Comments

The problem is the contrary. Want 100 rows, but all returns.
I am only guessing, OP's current query returns TOP 100 and he/she is not happy and says something like " I am all the rows back, not the last 100." :S so I am guessing he/she wants all the rows back not only the TOP 100 rows.
Well see its comment in the question above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.