All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#教程: 注册表的结构
什么是.net的接口和抽象类_[Asp.Net教程]
Asp.net的HttpCookie写入汉字读取时为乱码的解决方法_.net资料_编程技术
Div布局中如何实现自适应高度_[Html教程]
delphi异常处理Raise 语句
如何使用delphi调用外部EXE文件
C#动态生成树型结构的Web程序设计_.net资料_编程技术
网页中插入视频播放代码全集_JavaScript技术_编程技术
用sql存储过程实现前台标题变色_[SQL Server教程]
PHP网站开发中关于包含路径问题的解决方案_[PHP教程]
Reading number is top 10 pictures
NeedWallpaper4
5 meters long centenarians python and melee was successfully capture king snake (figure)
这才是真正的人体艺术2
The hot big eye big breast beauty2
这只猪到底犯了什么错?
看看什么叫美景
Female model behind the bitterness, often being overcharged5
教你做读书笔记
BingBingFan apple dew point photo gallery4
The money of more than 100 countries and regions19
Download software ranking
Boxer Classic video2
SQL2000 For 4IN1
软件工程思想
C++教程第四版
Be there or be square
Tram sex maniac 2 (H) rar bag5
Boxer's Top ten classic battle6
网络管理员第三版
Popkart Cracked versions Mobile phone games
株洲本地在线棋牌游戏
delv published in(发表于) 2014/1/16 9:34:46 Edit(编辑)
随机显示数据库记录_[Asp.Net教程]

随机显示数据库记录_[Asp.Net教程]

随机显示数据库记录_[Asp.Net教程]























System名称空间有一个Random类,用来产生随机数。本文就介绍利用这个Random类来随机显示数据库记录。




Random类有一个重载方法叫Next,它可以产生随机数,它允许输入两个参数,以产生这两个数之间的随机数。例如:




Random R = new Random();
Random.Next(1,100);







将会在产生1-100之间的随机数。




要随机显示数据库记录,需要知道数据库最大记录数和最小记录数。




int RecNo=0,MaxRecNo,MinRecNo;
Random R = new Random();
SqlDataReader DR;
SqlConnection CN = newSqlConnection("Server=Mengxianhui;Database=Northwind;uid=sa");
CN.Open();
SqlCommand Cmd = new SqlCommand("select Max(ProductId) as MaxProdid ,Min(ProductId) as MinProdId from Products",CN);
DR= Cmd.ExecuteReader();
DR.Read();
MaxRecNo = (int)DR["MaxProdid"] ;
MinRecNo = (int)DR["MinProdid"] ;
RecNo = R.Next(MinRecNo,MaxRecNo);





然后得到随机得到记录。




Cmd = new SqlCommand("select * from Products Where ProductID = " + RecNo,CN);
DR = Cmd.ExecuteReader();
DR.Read();
Response.Write("今日的产品名称: " +DR["ProductID"] + " - " + DR["ProductName"] + "");
CN.Close();




完整代码如下:
<%@ Page Language="C#" Debug="true" %>
<%@Import NameSpace="System.Data.SqlClient"%>
<%@Import NameSpace="System.Data"%>


随机显示数据库记录








来源:孟宪会之精彩世界













































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.