ASP.NET选择随机产品 [英] ASP.NET select random products

查看:75
本文介绍了ASP.NET选择随机产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hellow,



我正在asp.net 4.5上实现一个网站,我有一个带有列的表数据库产品(id,name,size,price ,日期,数量)我输入了一些物品。



我的问题是如何在我的home.aspx中预览(每次6个随机物品(不同或更改)自动随机)我的home.aspx)。



提前获得Thnx!

解决方案

I建议在数据库查询中随机选择产品,而不是在asp.net中。如果你使用SQL Server作为数据库,那么这样的东西会有所帮助:

  SELECT   TOP   6  * 
FROM YourTable
ORDER BY NEWID()



NewID随机样本

请看以下链接: http:// msdn .microsoft.com / zh-CN / library / cc441928.aspx [ ^ ]



另外,谷歌tsql random sample获得更多帮助



这是一个有趣的问题,祝你好运!


Jason,

假设您知道DB中有多少条目和

该条目有ID的

如果你使用

  Dim  r 作为 随机
r。下一步 0 100



在VB中





随机r =  new  Random(); 
r.Next( 0 100 );


C#中的
然后你可以从你的数据库中选择一个随机ID。



我认为你可以弄清楚如何在一些

代码中使用Random来获得六个。



Grtz

Tom


Hellow,

I'm implemeting a web site on asp.net 4.5, i have a table database products with columns (id,name,size,price,date,quantity) where i have imported some items.

My question is how can i preview in my home.aspx(6 random items every time (different or change automatically randomly) my home.aspx).

Thnx in advance for your time!

解决方案

I would suggest doing the random selection of products in your DB query not in asp.net. If you are using SQL Server for the DB, then something like this will help:

SELECT TOP 6 *
  FROM YourTable
  ORDER BY NEWID()


The NewID does the random sample
See this link: http://msdn.microsoft.com/en-us/library/cc441928.aspx[^]

Also, Google "tsql random sample" for more help

That was an interesting question, good luck!


Jason,
Assuming that you know how many entry's there are in the DB and
that the entry's have ID's
If you use

Dim r As New Random
       r.Next(0, 100)


In VB
Or

Random r = new Random();
   r.Next(0,100);


in C# then you can pick a random ID from your DB.

I think you can figure out how to use Random in some
code to take six.

Grtz
Tom


这篇关于ASP.NET选择随机产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆