Asyraf MN

Asyraf MN

  • NA
  • 28
  • 7.8k

How to display Label Letter By Letter In C#

Apr 4 2018 1:32 AM

Currently i'm working on Lucky Draw System. I've already can call out the data from database and display it using label. But how can i make it display one by one in label to make the system more interesting.

This is my 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.     protected void Button1_Click(object sender, EventArgs e)  
  26.     {  
  27.         string query = "SELECT TOP 1[EMP_ID]FROM EMPLOYEES WHERE[Attendance] = 'Present'ORDER BY NEWID()";  
  28.   
  29.         using (SqlConnection con = new SqlConnection(constr))  
  30.         {  
  31.             using (SqlCommand cmd = new SqlCommand(query))  
  32.             {  
  33.                 using (SqlDataAdapter sda = new SqlDataAdapter())  
  34.                 {  
  35.                     cmd.Connection = con;  
  36.                     sda.SelectCommand = cmd;  
  37.                     using (DataTable dt = new DataTable())  
  38.                     {  
  39.                         sda.Fill(dt);  
  40.                         if (dt.Rows.Count > 0)  
  41.                         {  
  42.                               
  43.                                     Label1.Text = dt.Rows[0]["EMP_ID"].ToString();  
  44.   
  45.                         }  
  46.                         else  
  47.                         {  
  48.                             Label1.Text += "Cannot draw! ";  
  49.                         }  
  50.                     }  
  51.                 }  
  52.             }  
  53.         }  
  54.     }  
  55. }  
  56.       
 

Answers (2)