Exemplo n.º 1
0
        //修改
        public int ModifyStudent(student objStudent)
        {
            //编写sql语句
            StringBuilder sqlB = new StringBuilder();

            sqlB.Append("update students set studentName='{0}',Gender='{1}',Birthday='{2}',");
            sqlB.Append("studentIdNo='{3}',PhoneNumber='{4}',studentAddress='{5}',classId={6} ");
            sqlB.Append(" where studentId={7}");
            //解析对象
            string sql = string.Format(sqlB.ToString(), objStudent.StudentName, objStudent.Gender, objStudent.Birthday,
                                       objStudent.StudentIdNo, objStudent.PhoneNumber, objStudent.StudentAddress,
                                       objStudent.ClassId, objStudent.StudentId);

            try
            {
                return(Convert.ToInt32(MysqlHelper.Update(sql)));
            }
            catch (MySqlException ex)
            {
                throw new Exception("数据库操作异常:" + ex.Message);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 2
0
        //删除
        public int DeleteStudent(string studentId)
        {
            String sql = "delete from students where studentId='{0}'";

            sql = string.Format(sql, studentId);
            try
            {
                return(Convert.ToInt32(MysqlHelper.Update(sql)));
            }
            catch (MySqlException ex)
            {
                throw new Exception("数据库操作异常:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        //添加
        public int AddStudent(student objStudent)
        {
            //编写语句
            StringBuilder sqlB = new StringBuilder();

            sqlB.Append("INSERT INTO students(StudentId, StudentName, Gender, Birthday, StudentIdNo, Age,PhoneNumber,StudentAddress,CardNo,ClassId) VALUES");
            sqlB.Append("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')");
            string sql = string.Format(sqlB.ToString(), objStudent.StudentId, objStudent.StudentName,
                                       objStudent.Gender, objStudent.Birthday, objStudent.StudentIdNo, objStudent.Age, objStudent.PhoneNumber,
                                       objStudent.StudentAddress, objStudent.CardNo, objStudent.ClassId);

            try {
                return(Convert.ToInt32(MysqlHelper.Update(sql)));
            }
            catch (MySqlException ex)
            {
                throw new Exception("数据库操作异常:" + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }