Beispiel #1
0
        public void ListUpdate()
        {
            Courses.Add("-");
            Professors.Add("-");
            SqlConnection sqlConnection = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=TeachersTimetable;");

            sqlConnection.Open();
            SqlCommand command = sqlConnection.CreateCommand();

            command.CommandText = "select name from " + Tables[5];
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable      data    = new DataTable();

            adapter.Fill(data);
            foreach (DataRow row in data.Rows)
            {
                string str = row[0].ToString().Trim();
                if (!Professors.Contains(str))
                {
                    Professors.Add(str);
                }
            }

            command.CommandText = "select name from " + Tables[2];
            adapter             = new SqlDataAdapter(command);
            data = new DataTable();
            adapter.Fill(data);
            foreach (DataRow row in data.Rows)
            {
                string str = row[0].ToString().Trim();
                if (!Courses.Contains(str))
                {
                    Courses.Add(str);
                }
            }

            Courses.Sort();
            Professors.Sort();
        }