C # page Lottery instance ASP.

Source: Internet
Author: User

<! DOCTYPE html>

Not much nonsense directly on the code, above is the page code

Start a lottery
private void Drawstart () {var dt = gstlist (). Tables[0]; StringBuilder sb = new StringBuilder (); foreach (DataRow r in dt. Rows) {sb. Append ("<li><div class= ' divname ' >" + r["UserName"]. ToString () + "</div></li>"); Sb. Append ("<li><div class= ' Divcompany ' >" + r["Company"]. ToString () + "</div></li>"); } userlist = sb. ToString (); }
Stop draw private void drawend () {var dt = Gstoneanddraw (). Tables[0]; StringBuilder sb = new StringBuilder (); foreach (DataRow r in dt. Rows) {sb. Append ("<li><div class= ' divname ' >" + r["UserName"]. ToString () + "</div>"); Sb. Append ("<div class= ' Divcompany ' >" + r["Company"]. ToString () + "</div></li>"); } userlist = sb. ToString (); }

Get a list of lottery people randomly get data for 100 people Private DataSet Gstlist () {using (SqlConnection connection = new SqlConnection (conne ctionstring)) {DataSet ds = new DataSet (); try {connection. Open (); var SQLString = "Select top from [T_phoneno] where [hasdraw]=0 order by NEWID ()"; SqlDataAdapter command = new SqlDataAdapter (SQLString, connection); Command. Fill (ds, "DS"); } catch (System.Data.SqlClient.SqlException ex) {throw new Exception (ex). Message); } return DS; } }

Randomly gets an award-winning, and modifies the winning state private DataSet Gstoneanddraw () {using (SqlConnection connection = new SqlConnection (con nectionstring)) {DataSet ds = new DataSet (); try {connection. Open (); var SQLString = "SELECT top 1 * from [T_phoneno] where [hasdraw]=0 order by NEWID ()"; SqlDataAdapter command = new SqlDataAdapter (SQLString, connection); Command. Fill (ds, "DS"); if (ds. Tables[0]. Rows.Count > 0) {string sqlstr = "Update T_phoneno set [hasdraw]=1 WHERE [id]=" + D S.tables[0]. rows[0]["ID"]; SqlCommand com = new SqlCommand (sqlstr, connection); Int J = com. ExecuteNonQuery (); if (J > 0) {}}} catch (System.Data.SqlClient.SqlException ex {throw new Exception (ex). Message); } return DS; } }
Click Draw event protected void Btndraw_click (object sender, EventArgs e) {if (Btndraw.text = = "Start") { Drawstart (); Btndraw.text = "End"; Return } if (Btndraw.text = = "End") {drawend (); Btndraw.text = "Start"; Return } }

  

Backstage code as above, caught dead, direct use of ADO, colleagues to the project I just realized this function, we laughed at

C # page Lottery instance ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.