Example #1
0
        public bool addStudent(StudentClass s)
        {
            bool flag = false;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     DB  = new Dbhelper(con);
                SqlParameter pNo = new SqlParameter {
                    ParameterName = "@sNo", SqlDbType = SqlDbType.Char, Value = s.sNo
                };
                SqlParameter pName = new SqlParameter {
                    ParameterName = "@sName", SqlDbType = SqlDbType.Char, Value = s.sName
                };
                SqlParameter pPass = new SqlParameter {
                    ParameterName = "@sPass", SqlDbType = SqlDbType.Char, Value = s.sPass
                };
                try
                {
                    if (DB.ExecuteSQL("insert into students(sNo,sName,sPass)values(@sNo,@sName,@sPass)", pNo, pName, pPass) > 0)
                    {
                        flag = true;
                    }
                }
                catch { }
                con.Close();
            }
            return(flag);
        }
Example #2
0
        //获取表“Subjects”中的所有数据
        public DataTable getSubjectDataTable()
        {
            DataTable dt = new DataTable("Subjects");

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper       helper  = new Dbhelper(con);
                SqlDataAdapter adapter = helper.GetAdapter("select * from Subjects order by sSubject");
            }
            return(dt);
        }
Example #3
0
        public DataTable getStudentDataTable()
        {
            DataTable dt = new DataTable("Students");

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper       DB      = new Dbhelper(con);
                SqlDataAdapter adapter = DB.GetAdapter("select*from Students order by sNo");
                adapter.Fill(dt);
                con.Close();
            }
            return(dt);
        }
Example #4
0
        //删除课程,返回布尔值,是否删除成功
        public bool deleteSubject(SubjectClass subject)
        {
            bool flag = false;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     helper = new Dbhelper(con);
                SqlParameter pID    = new SqlParameter {
                    ParameterName = "@sID", SqlDbType = System.Data.SqlDbType.Int, Value = subject.ID
                };
                if (helper.ExecuteSQL("delete from Subjects where sID=@sID ", pID) > 0)
                {
                    flag = true;
                }
                con.Close();
            }
            return(flag);
        }
Example #5
0
        //添加课程,返回课程id
        public int addSubject(ref SubjectClass suject)
        {
            int ID = 0;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     helper   = new Dbhelper(con);
                SqlParameter pSubject = new SqlParameter {
                    ParameterName = "@sSubject", SqlDbType = System.Data.SqlDbType.VarChar, Value = suject.sSubject
                };
                if (helper.ExecuteSQL("insert into Subjects (sSubject) values(@sSubject)", pSubject) > 0)
                {
                    ID = helper.GetScalar("select top 1 sID from Subjects order by sID desc");
                }
                con.Close();
            }
            return(ID);
        }
Example #6
0
        public bool deleteStudent(StudentClass Student)
        {
            bool flag = false;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     DB  = new Dbhelper(con);
                SqlParameter pNo = new SqlParameter {
                    ParameterName = "@sNo", SqlDbType = SqlDbType.Char, Value = Student.sNo
                };
                if (DB.ExecuteSQL("delete from students where sNo=@sNo", pNo) > 0)
                {
                    flag = true;
                }
                con.Close();
            }
            return(flag);
        }
Example #7
0
        //更新课程(根据课程iid更新课程名)
        public bool updateSubject(SubjectClass subject)
        {
            bool flag = false;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     helper = new Dbhelper(con);
                SqlParameter pID    = new SqlParameter {
                    ParameterName = "@sID", SqlDbType = System.Data.SqlDbType.Int, Value = subject.ID
                };
                SqlParameter pSubject = new SqlParameter {
                    ParameterName = "@sSubject", SqlDbType = System.Data.SqlDbType.VarChar, Value = subject.sSubject
                };
                if (helper.ExecuteSQL("update Subjects set sSubject=@sSubject where sID=@sID", pSubject, pID) > 0)
                {
                    flag = true;
                }
            }
            return(flag);
        }
Example #8
0
        public bool updateStudent(StudentClass Student)
        {
            bool flag = false;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     DB  = new Dbhelper(con);
                SqlParameter pNo = new SqlParameter {
                    ParameterName = "@sNo", SqlDbType = SqlDbType.Char, Value = Student.sNo
                };
                SqlParameter pName = new SqlParameter {
                    ParameterName = "@sName", SqlDbType = SqlDbType.Char, Value = Student.sName
                };
                SqlParameter pPass = new SqlParameter {
                    ParameterName = "@sPass", SqlDbType = SqlDbType.Char, Value = Student.sPass
                };
                if (DB.ExecuteSQL("update students set sName=@sName,sPass=@sPass where sNo=@sNo", pNo, pName, pPass) > 0)
                {
                    flag = true;
                }
                con.Close();
            }
            return(flag);
        }