public int Addstudent(StudInfo1 student) { try { Exercise_ERContainer cn = new Exercise_ERContainer(); if (cn.StudInfo1Set.Find(student.studentid) == null) { cn.StudInfo1Set.Add(student); } cn.SaveChanges(); return(1); } //catch (DbEntityValidationException ex) catch (Exception ex) { Console.WriteLine(ex.Message); return(0); } }
////endfromexcel////////////////// /////save student to db /////save student to db public static void savestudents(int classid) { Service_stuClient serviceDB = new Service_stuClient(); List <Exercise_DAL.class_student> c_studl = new List <Exercise_DAL.class_student>(); List <Exercise_DAL.StudInfo1> studentl = new List <Exercise_DAL.StudInfo1>(); foreach (Student st in studentList) { Exercise_DAL.StudInfo1 sttemp = new Exercise_DAL.StudInfo1(); sttemp.studentid = st.studentid; sttemp.name = st.name; sttemp.pd = "11111111"; Exercise_DAL.class_student c_st = new Exercise_DAL.class_student(); c_st.classid = classid; c_st.studentid = st.studentid; c_st.classno = st.no; c_studl.Add(c_st); studentl.Add(sttemp); } serviceDB.Addstu(c_studl, studentl); /////////////////////////////////////////////// }