{"id":2033,"date":"2012-05-24T14:54:34","date_gmt":"2012-05-24T18:54:34","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=2033"},"modified":"2012-05-24T14:54:34","modified_gmt":"2012-05-24T18:54:34","slug":"random-db-record-generating-script","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2012\/05\/random-db-record-generating-script\/","title":{"rendered":"Random db record generating script"},"content":{"rendered":"<p>Generate random db record output. This is classic asp script. VB.NET version is coming soon<\/p>\n<pre>\r\n<code>\r\n&lt; % @ Language=\"VBScript\" %>\r\n&lt; % Option Explicit %> \r\n&lt; !DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Strict\/\/EN\" \r\n\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd\">\r\n&lt;html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"en\">\r\n&lt;head runat=\"server\">\r\n    &lt;title>\r\n    &lt;link href=\"Styles\/Site.css\" rel=\"stylesheet\" type=\"text\/css\" \/>\r\n&lt;\/head>\r\n&lt;body>\r\n    &lt;div class=\"page\">\r\n    &lt;div class=\"main\">\r\n    &lt;div style=\"width: 900px; text-align: right;\">\r\n    &lt;input type=\"button\" Value=\"Back to Home\" \r\n    OnClick=\"window.location.href='http:\/\/my_website\/home.aspx'\" \r\n    class=\"button blue\"\/>\r\n                \r\n    &lt;% \r\n    'declare your variables\r\n    dim connection, recordset, sConnString, sql\r\n    dim intRandomNumber, intTotalRecords, i\r\n                \r\n    'declare SQL statement that will query your database\r\n     sql = \"SELECT * FROM ob_feedback\"\r\n                \r\n     'create ADO connection and recordset object\r\n     Set connection = Server.CreateObject(\"ADODB.Connection\")\r\n    Set recordset = Server.CreateObject(\"ADODB.Recordset\") \r\n                \r\n   'define the connection string, specify database \r\n   ' driver and the location of database\r\n   sConnString=\"PROVIDER=Microsoft.ACE.OLEDB.12.0; &_\r\n    Data Source=\" & Server.MapPath(\"App_Data\\ob_db.accdb\") \r\n                \r\n   'Open the connection to the database\r\n   connection.Open(sConnString)\r\n                \r\n   'Open the recordset object executing the SQL \r\n   recordset.Open sql, connection, 3, 1\r\n   'count the number of records and hold this is the variable intTotalRecords\r\n   intTotalRecords = recordset.RecordCount\r\n   Randomize()\r\n   intRandomNumber = Int(intTotalRecords * Rnd)\r\n   'move to the random number returned\r\n    recordset.Move intRandomNumber\r\n   'open the table\r\n   'header\r\n    Response.Write(\"<p>Drawing a winner\")\r\n    'running a job\r\n    'def var\r\n    Dim job\r\n    job = Request.QueryString(\"do\")\r\n\tIf job = \"go\" Then\r\n\tResponse.write(\"&lt;table style='border: gray 1px solid;' >&lt;tr>\")\r\n        'loop through the total number of fields\r\n        For i = 0 to recordset.Fields.Count - 1\r\n        'write out the field value\r\n        Response.write(\"&lt;td>\" & recordset(i) & \"\")\r\n        Next\r\n        'close the table\r\n        response.write \"\"\r\n        End If\r\n        'close the recordset and connection objects and free up resources\r\n        recordset.Close\r\n        Set recordset=Nothing\r\n        connection.close\r\n         Set connection=Nothing\r\n     %>\r\n     &lt;div style=\"min-height: 20px;\"> \r\n     &lt;div style=\"width: 900px; text-align: center;\"> \r\n     &lt;input type=\"button\" Value=\"Generate\"\r\n     OnClick=\"window.location.href='http:\/\/my_website\/drawing.asp?do=go'\" \r\n     class=\"button blue\"\/>\r\n     &lt;div class=\"clear\">\r\n     &lt;div class=\"footer\">\r\n       \r\n&lt;\/body>\r\n&lt;\/html>\r\n\r\n<\/p><\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Generate random db record output. This is classic asp script. VB.NET version is coming soon &lt; % @ Language=&#8221;VBScript&#8221; %> &lt; % Option Explicit %> &lt; !DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Strict\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd&#8221;> &lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221; xml:lang=&#8221;en&#8221;> &lt;head runat=&#8221;server&#8221;> &lt;title> &lt;link href=&#8221;Styles\/Site.css&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text\/css&#8221; \/> &lt;\/head> &lt;body> &lt;div class=&#8221;page&#8221;> &lt;div class=&#8221;main&#8221;> &lt;div style=&#8221;width: 900px; text-align: [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,33,67],"tags":[30,34,98,96,97],"class_list":["post-2033","post","type-post","status-publish","format-standard","hentry","category-access","category-classic-asp","category-sql","tag-access-2","tag-classic-asp-2","tag-generate","tag-random","tag-record"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2033"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=2033"}],"version-history":[{"count":11,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2033\/revisions"}],"predecessor-version":[{"id":2067,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2033\/revisions\/2067"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=2033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=2033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=2033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}