Пример #1
0
        /// <summary>
        /// 将集合中的对象插入到数据库
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool Import(List <Student> list)
        {
            List <string> sqlList    = new List <string>();
            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.Append("insert into Students(studentName,Gender,Birthday,");
            sqlBuilder.Append("StudentIdNo,Age,PhoneNumber,StudentAddress,CardNo,ClassId)");
            sqlBuilder.Append(" values('{0}','{1}','{2}',{3},{4},'{5}','{6}','{7}',{8})");
            foreach (Student objStudent in list)
            {
                string sql = string.Format(sqlBuilder.ToString(), objStudent.StudentName,
                                           objStudent.Gender, objStudent.Birthday,
                                           objStudent.StudentIdNo, objStudent.Age,
                                           objStudent.PhoneNumber, objStudent.StudentAddress, objStudent.CardNo,
                                           objStudent.ClassId);
                sqlList.Add(sql);
            }
            return(SQLHelper.UpdateByTran(sqlList));
        }