<%@ Page language=" c#" %> <! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load (object sender, EventArgs e) {Random rnd = new Random (unchecked ((int) DateTime.Now.Ticks)); int Intrandomnumber = rnd. Next (); String ConnectionString = @" Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|\aspxweb.mdb; Persist Security info=true"; String sql = "select Top title,objectguid from Document order by Rnd (" + ( -1 * intrandomnumber) + &am P;quot;*id) "; System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection (ConnectionString); cn. Open (); System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand (SQL, CN); System.Data.OleDb.OleDbDataReader dr = cmd. ExecuteReader (System.Data.CommandBehAvior. CloseConnection); Gridview1.datasource = Dr; Gridview1.databind (); Dr. Close (); Cmd. Dispose (); cn. Dispose (); cn = NULL; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title> randomly read Access database records </title> </head> <body> <form id="form1" Runat="server"> <div> <asp:gridview id=" gridview1" runat="server" Autogeneratecolumns="false"> < Columns> <asp:hyperlinkfield datanavigateurlfields="objectguid" headertext=" Articles " datatextfield=" title" datanavigateurlformatstring="http://dotnet.aspx.cc/article/{0}/read.aspx" /> </Columns> </asp:GridView> </div> </form& gt; </body> </html>
Vb. NET:
<%@ Page language=" vb" debug="true" %> <! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load (ByVal sender as Object, ByVal e as System.EventArgs) Dim timestring as String = DateTime.Now.Ticks . ToString () Dim A As UInt32 = Uint32.parse (timestring.substring (timestring.length-8, 8)) Dim b As Int32 = Bitconverter.to Int32 (Bitconverter.getbytes (a), 0) Dim rnd As Random = New Random (b) Dim intrandomnumber As Integer = rnd. Next Response.Write (intrandomnumber) Dim ConnectionString as String = " Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|\aspxweb.mdb; Persist Security info=true" Dim SQL as String = "select top title,objectguid from Document order by Rnd (" + ( -1 * intrandomnumber ). ToString () +; quot;*id) " Dim cn as System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection (ConnectionString) CN. Open () Dim cmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand (SQL, CN) Dim dr As System.Data.OleDb . OleDbDataReader = cmd. ExecuteReader (System.Data.CommandBehavior.CloseConnection) Gridview1.datasource = Dr Gridview1.databind () Dr. Close () cmd. Dispose () CN. Dispose () cn = Nothing End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id=" head1" Runat="server"> <title> randomly read Access database records </title> </head> <body> <form id="form1" Runat="server"> <div> <asp:gridview id=" gridview1" runat="server" Autogeneratecolumns="false"> < Columns> <asp: HyperLinkField datanavigateurlfields="objectguid" headertext=" Articles " datatextfield=" title" datanavigateurlformatstring="http://dotnet.aspx.cc/article/{0}/read.aspx" /> </Columns> </asp:GridView> </div> </form> </body> </html>