private void addItems(string name) { if (name == null || name.Equals("")) { dataGridView1.DataSource = null; dataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = Cache.students; } else { dataGridView1.DataSource = null; dataGridView1.AutoGenerateColumns = false; Students tempStudents = new Students(); foreach (Student stud in Cache.students) { if (stud.Fullname.ToUpper().Contains(name.ToUpper())) tempStudents.Add(stud); } dataGridView1.DataSource = tempStudents; } }
public Students GetStudents() { Students students = new Students(); try { using (SqlConnection conn = new SqlConnection(connString)) using (SqlCommand comm = new SqlCommand("usp_GetActiveCustomers", conn)) { comm.CommandType = CommandType.StoredProcedure; conn.Open(); using (SqlDataReader dr = comm.ExecuteReader()) { while (dr.Read()) { Student stud = new Student(dr["Customer Number"].ToString(), dr["Customer Name"].ToString(), dr["Price Level"].ToString(), dr["Customer Class"].ToString(), dr["Currency ID"].ToString(), dr["Grade Level"].ToString(), dr["Status"].ToString()); students.Add(stud); } } } } catch (Exception ex) { log.Error(ex); throw; } return students; }