How to select 10 random records from my SQLServer DataBase?
ASP.NET
3
Posts
3
Posters
0
Views
1
Watching
-
Fill up the dataset (ds) with data
Random R =new Random(); int I; int MaxLimit = ds.Tables[0].Rows.Count; int MinLimit = 0; for(I = 0; I < 10; I++) Response.Write(ds.Tables[0].Rows[R.Next(MinLimit,MaxLimit)]["name"];
--------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done. -
I would do it in your SQL query rather than in C#. select top 10 * from products order by newid() Try that on your northwind database and look at the difference if you leave off the order by newid(). Doing it with the SQL means that you don't have to pull back everything in your DS if your only looking for 10 random records. KingXango