这是我的课堂记录,可以是老师和学生的主/详细/详细记录
class Record
{
public string RecorNo { get; set; }
private List<Teacher> _Student = new List<Teacher>();
public List<Teacher> Teacher
{
get { return _Teacher; }
set { _Teacher=value; }
}
}
class Teacher
{
private string _TeacherName;
public Teacher(string teachername)
{
_TeacherName = teachername;
}
public string TeacherName
{
get { return _TeacherName; }
set { _TeacherName = value; }
}
private List<Students> _students = new List<Students>();
public List<Students> Students
{
get { return _students;}
set { _students = value;}
}
}
class Details
{
private string _studentname;
public Details(string studentsname)
{
_studentsname = studentsname;
}
我在 2 个 datagridview 中绑定了教师/学生,如下所示:
TeacherBindingSource.DataSource = record.Teacher;
StudentBindingSourcce.DataSource = TeacherBindingSource;
StudentBindingSourcce.DataMember = "Student";
dataGridView1.DataSource =TeacherBindingSource;
dataGridView2.DataSource = StudentBindingSourcce;
现在我失去了如何保存这条记录。
如何将其保存到数据库中?我想拥有一个。
record.Save(); method that will save the whole object.
我可以遍历列表并一一插入,但记录可能已经存在于数据库中,所以我必须知道添加、更新或删除了哪条记录?
此外,如何制作一种填充教师/学生列表的方法,例如:
records.LoadTeachers();
records.Teacher("Smith").LoadStudents();