Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void download_marks_from_list()
- {
- // 0. Connecting to database
- string connetionString = null;
- SqlConnection conn;
- connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=tomass;Integrated Security=True";
- conn = new SqlConnection(connetionString);
- conn.Open();
- // Variable - name of class
- var nazwa_przedmiotu = DropDownList1.SelectedValue;
- // 1. declare command object with parameter
- SqlCommand cmd = new SqlCommand(
- "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);
- // 2. define parameters used in command object
- SqlParameter param = new SqlParameter();
- param.ParameterName = "@Nazwa";
- param.Value = nazwa_przedmiotu;
- // 3. add new parameter to command object
- cmd.Parameters.Add(param);
- List<int> list = new List<int>();
- Label3.Text = " ";
- using (var reader = cmd.ExecuteReader())
- {
- while (reader.Read())
- {
- list.Add(reader.GetInt32(0));
- }
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (i == list.Count - 1)
- {
- Label3.Text += list[i];
- }
- else
- {
- Label3.Text += list[i] + ", ";
- }
- }
- conn.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement