Asyraf MN

Asyraf MN

  • NA
  • 28
  • 6.9k

How to display lucky draw result on a table

Apr 22 2018 8:21 PM
Hi, currently i'm working on lucky draw system. My system are functioning well but i just want to add one features that is it can display a lucky draw result on a table in another page at the same time. Previously, when user click on button draw at the system, it will display out the result at the page. So, how to make the result display on table in another page at the same time when user click button draw?
 
This is my lucky draw code : 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. using System.IO;  
  7. using System.Linq;  
  8. using System.Web;  
  9. using System.Web.UI;  
  10. using System.Web.UI.WebControls;  
  11.   
  12.   
  13.   
  14.   
  15. public partial class _Default : System.Web.UI.Page  
  16.   
  17. {  
  18.     string constr = ConfigurationManager.ConnectionStrings["lucky"].ConnectionString;  
  19.     protected void Page_Load(object sender, EventArgs e)  
  20.     {  
  21.   
  22.   
  23.     }  
  24.   
  25.     static List<string> list = new List<string>();  
  26.     protected void Button1_Click(object sender, EventArgs e)  
  27.     {  
  28.         string query = "SELECT TOP 1[Emp_id]FROM Emp_Info WHERE[Attendance] = 'Present'ORDER BY NEWID()";  
  29.   
  30.         using (SqlConnection con = new SqlConnection(constr))  
  31.         {  
  32.             using (SqlCommand cmd = new SqlCommand(query))  
  33.             {  
  34.                 using (SqlDataAdapter sda = new SqlDataAdapter())  
  35.                 {  
  36.                     cmd.Connection = con;  
  37.                     sda.SelectCommand = cmd;  
  38.                     using (DataTable dt = new DataTable())  
  39.                     {  
  40.                         sda.Fill(dt);  
  41.                         if (dt.Rows.Count > 0)  
  42.                         {  
  43.   
  44.                             if (list.Any(x => x.Equals(dt.Rows[0]["Emp_id"].ToString())))  
  45.                             {  
  46.                                   
  47.                                 //Label1.Text += "is duplicate";  
  48.                             }  
  49.                             else  
  50.                             {  
  51.                                 list.Add(dt.Rows[0]["Emp_id"].ToString());  
  52.                                 Label1.Text = dt.Rows[0]["Emp_id"].ToString();  
  53.                             }  
  54.   
  55.   
  56.                         }  
  57.                         else  
  58.                         {  
  59.                             Label1.Text += "Cannot draw! ";  
  60.                         }  
  61.                     }  
  62.                 }  
  63.             }  
  64.         }  
  65.     }  
  66. }