Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Collections;
  8. using System.Data.SqlClient;
  9.  
  10. namespace eDziennik1
  11. {
  12.     public partial class Default : System.Web.UI.Page
  13.     {
  14.         protected void Page_Load(object sender, EventArgs e)
  15.         {
  16.             Label2.Text = " ";
  17.             string connetionString = null;
  18.             SqlConnection conn;
  19.             connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=tomass;Integrated Security=True";
  20.             conn = new SqlConnection(connetionString);
  21.  
  22.             conn.Open();
  23.             string result = "SELECT Ocena FROM Oceny";
  24.             SqlCommand showresult = new SqlCommand(result, conn);
  25.  
  26.             List<int> list = new List<int>();
  27.  
  28.             using (var reader = showresult.ExecuteReader())
  29.             {
  30.                 while (reader.Read())
  31.                 {
  32.                     list.Add(reader.GetInt32(0));
  33.                 }
  34.             }
  35.  
  36.             for (int i = 0;  i < list.Count; i++)
  37.             {
  38.                
  39.                 if (i == list.Count - 1)
  40.                 {
  41.                     Label2.Text += list[i];
  42.                 }
  43.                 else
  44.                 {
  45.                     Label2.Text += list[i] + ", ";
  46.                 }
  47.             }
  48.  
  49.             conn.Close();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement