I have 20000 products in DB. Want to show 20 on load and rest others onclick button. I dont want to load all the 20000 initially. Please advise
Asked
Active
Viewed 70 times
-1
-
Why don't you use `Top` for selecting top 20 records? – sujith karivelil Sep 11 '15 at 04:58
-
2Using `SqlCommand`, `Entity Framework`? – Reza Aghaei Sep 11 '15 at 04:59
-
Use `LIMIT` clause in SQL Query. `SELECT * FROM TABLE1 LIMIT 20` at the time loading. Then on the button click event, `SELECT * FROM TABLE1`. – DhavalR Sep 11 '15 at 05:01
-
If this is Oracle SQL remember to use `SELECT * FROM TABLE1 WHERE ROWNUM < 20` or similar – FiringSquadWitness Sep 11 '15 at 05:03
-
FYI it's called pagination http://stackoverflow.com/q/109232/800613 – Atomosk Sep 11 '15 at 05:30
3 Answers
1
You can use something like
SELECT TOP 20 * FROM yourTable;
This link gives more information about Top

sujith karivelil
- 28,671
- 6
- 55
- 88
1
You can use linq instead, since it does not bother about the syntax that the db expects(using LIMIT/TOP in select query).
var query=(from c in context.yourTable
select c).Take(20).AsNoTracking().ToList();

Nikita Shrivastava
- 2,978
- 10
- 20
0
Select * from ( Select row_number() Over(Order by Columnname) rw,* from Tablename ) t where t.rw between 1 and 20

sunny singla
- 11
- 1