Because the Access database record set is cached, Random Access database records obtained from the Code cannot be obtained. You need to use a random SQL statement to eliminate the cache. The following is an example: voidPage_Load (Objectsrc, EventArgse) {if (! IsPostBack) {stringMyConnStringProviderMicrosoft. Jet. Ole
Because the Access database record set is cached, Random Access database records obtained from the Code cannot be obtained. You need to use a random SQL statement to eliminate the cache. The following is an example: voidPage_Load (Objectsrc, EventArgse) {if (! IsPostBack) {stringMyConnString = Provider = Microsoft. Jet. Ole
Because Access
Database
RecordThe reason for the set cache, from the code
GetAccess
Database
Random
RecordYes.
RandomSQL statement to eliminate the cache.
The following is an example:
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 No., TitleAs title 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">