记录随机显示数据库的办法

记录随机显示数据库的办法

privatevoidPage_Load(objectsender,System.EventArgse)
{

intRecNO,MaxRecNO,MinRecNO;
Randomrandom
=newRandom();
OleDbDataReaderodr;
OleDbConnectioncon
=newOleDbConnection();
con.ConnectionString
="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath("data/WebFormTest.mdb");
con.Open();
OleDbCommandcmd
=newOleDbCommand("selectMax(ProductID)asMaxProductID,Min(ProductID)asMinProductIDfromProducts",con);
odr
=cmd.ExecuteReader();
odr.Read();
MaxRecNO
=(int)odr["MaxProductID"];
MinRecNO
=(int)odr["MinProductID"];
odr.Close();
RecNO
=random.Next(MinRecNO,MaxRecNO);
cmd
=newOleDbCommand("select*fromProductswhereProductID="+RecNO,con);
odr
=cmd.ExecuteReader();
odr.Read();
Response.Write(
"产品名称:"+odr["ProductID"]+"-"+odr["ProductName"]);
odr.Close();
con.Close();
}