private void Page_Load(object sender, System.EventArgs e)
{
int RecNO, MaxRecNO, MinRecNO;
Random random = new Random();
OleDbDataReader odr;
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + Server.MapPath("data/WebFormTest.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("select Max(ProductID) as MaxProductID,Min(ProductID) as MinProductID from Products",con);
odr = cmd.ExecuteReader();
odr.Read();
MaxRecNO = (int)odr["MaxProductID"];
MinRecNO = (int)odr["MinProductID"];
odr.Close();
RecNO = random.Next(MinRecNO, MaxRecNO);
cmd = new OleDbCommand("select * from Products where ProductID = " + RecNO,con);
odr = cmd.ExecuteReader();
odr.Read();
Response.Write("产品名称:" + odr["ProductID"] + " - " + odr["ProductName"]);
odr.Close();
con.Close();
}
{
int RecNO, MaxRecNO, MinRecNO;
Random random = new Random();
OleDbDataReader odr;
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + Server.MapPath("data/WebFormTest.mdb");
con.Open();
OleDbCommand cmd = new OleDbCommand("select Max(ProductID) as MaxProductID,Min(ProductID) as MinProductID from Products",con);
odr = cmd.ExecuteReader();
odr.Read();
MaxRecNO = (int)odr["MaxProductID"];
MinRecNO = (int)odr["MinProductID"];
odr.Close();
RecNO = random.Next(MinRecNO, MaxRecNO);
cmd = new OleDbCommand("select * from Products where ProductID = " + RecNO,con);
odr = cmd.ExecuteReader();
odr.Read();
Response.Write("产品名称:" + odr["ProductID"] + " - " + odr["ProductName"]);
odr.Close();
con.Close();
}
2279

被折叠的 条评论
为什么被折叠?



