Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. protected void download_marks_from_list()
  2.         {
  3.             // 0. Connecting to database
  4.             string connetionString = null;
  5.             SqlConnection conn;
  6.             connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=tomass;Integrated Security=True";
  7.             conn = new SqlConnection(connetionString);
  8.             conn.Open();
  9.             // Variable - name of class
  10.             var nazwa_przedmiotu = DropDownList1.SelectedValue;
  11.             // 1. declare command object with parameter
  12.             SqlCommand cmd = new SqlCommand(
  13.             "SELECT Oceny.Ocena FROM Oceny INNER JOIN Przedmioty ON Oceny.Id_Przedmioty = Przedmioty.Id INNER JOIN Uczniowie ON Oceny.Id_Uczniowie = Uczniowie.Id WHERE Uczniowie.Imie='Aleksander' AND Przedmioty.Nazwa=@Nazwa", conn);
  14.             // 2. define parameters used in command object
  15.             SqlParameter param = new SqlParameter();
  16.             param.ParameterName = "@Nazwa";
  17.             param.Value = nazwa_przedmiotu;
  18.             // 3. add new parameter to command object
  19.             cmd.Parameters.Add(param);
  20.             List<int> list = new List<int>();
  21.             Label3.Text = " ";
  22.             using (var reader = cmd.ExecuteReader())
  23.             {
  24.                 while (reader.Read())
  25.                 {
  26.                     list.Add(reader.GetInt32(0));
  27.                 }
  28.             }
  29.  
  30.             for (int i = 0; i < list.Count; i++)
  31.             {
  32.  
  33.                 if (i == list.Count - 1)
  34.                 {
  35.                     Label3.Text += list[i];
  36.                 }
  37.                 else
  38.                 {
  39.                     Label3.Text += list[i] + ", ";
  40.                 }
  41.             }
  42.             conn.Close();
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement