由于access数据库记录集缓存的原因,从代码里得到access数据库随机记录是得不到,需要用随机sql语句的办法来消除缓存。下面就是例子:
voidpage_load(objectsrc,eventargse)
{
if(!ispostback)
{
stringmyconnstring=“provider=microsoft.jet.oledb.4.0;datasource=”
+server.mappath(”aspxweb.mdb.ascx”);
randomr=newrandom();
intintrandomnumber=r.next(1,1000);
stringsql=“selecttop10idas序号,titleas标题fromdocumentorderbyrnd(”
+(-1*intrandomnumber).tostring()+“*id)”;
oledbconnectionmyconnection=newoledbconnection(myconnstring);
myconnection.open();
oledbcommandcmd=newoledbcommand(sql,myconnection);
oledbdatareaderdr=cmd.executereader();
datagrid1.datasource=dr;
datagrid1.databind();
cmd.dispose();
myconnection.close();
myconnection.dispose();
myconnection=null;
}
}
width=”600px”runat=”server”font-size=”9pt”>
