Home > Database > Mysql Tutorial > 如何随机得到Access数据库记录

如何随机得到Access数据库记录

WBOY
Release: 2016-06-07 15:02:47
Original
1230 people have browsed it

由于Access 数据库 记录 集缓存的原因,从代码里 得到 Access 数据库 随机 记录 是得不到,需要用 随机 SQL语句的办法来消除缓存。 下面就是例子: voidPage_Load(Objectsrc,EventArgse) { if(!IsPostBack) { stringMyConnString=Provider=Microsoft.Jet.Ole

 由于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”>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template