如何从表行中获取随机值
问题描述:
我将表格中的数据放在一列中,并希望在ASP.NET 4.0 C#文本框上加载页面时从表格中随机选择一个数据.
i''ve data on table in one column and want to select one data from table randomly while loading a page on ASP.NET 4.0 C# textbox. how to do it
答
您没有提及是否要通过SQL查询,代码或其他方式来执行此操作,但是您想使用SQL,并且您拥有SQL Server,那么选择随机行的一种方法是
You didn''t mention if you want to do this with a SQL query or in code or something else, but if you want to use SQL and you have SQL Server then one way to select a random row is
SELECT TOP 1 * FROM YourTable ORDER BY NEWID()
感谢Mika,Wendelius和Wes Aday的良好响应.现在解决了
Thank you Mika, Wendelius, Wes Aday for your good response. It''s solved now