Beispiel #1
0
        //update
        public bool Update(subjectClass s)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //writing sql query
                string     sql = "UPDATE table_subject SET SubjectCode=@SubjectCode, SubjectName=@SubjectName, OfferedYear=@OfferedYear, OfferedSemester=@OfferedSemester, LectureHours=@LectureHours, TuteHours=@TuteHours, LabHours=@LabHours, EvolutionHours=@EvolutionHours WHERE No=@No";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@SubjectCode", s.SubjectCode);
                cmd.Parameters.AddWithValue("@SubjectName", s.SubjectName);
                cmd.Parameters.AddWithValue("@OfferedYear", s.OfferedYear);
                cmd.Parameters.AddWithValue("@OfferedSemester", s.OfferedSemester);
                cmd.Parameters.AddWithValue("@LectureHours", s.LectureHours);
                cmd.Parameters.AddWithValue("@TuteHours", s.TuteHours);
                cmd.Parameters.AddWithValue("@LabHours", s.LabHours);
                cmd.Parameters.AddWithValue("@EvolutionHours", s.EvolutionHours);
                cmd.Parameters.AddWithValue("@No", s.No);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }


            return(isSuccess);
        }
Beispiel #2
0
        //Insert
        public bool Insert(subjectClass s)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //writing sql query
                string     sql = "INSERT INTO table_subject (SubjectCode, SubjectName, OfferedYear, OfferedSemester, LectureHours, TuteHours, LabHours, EvolutionHours) VALUES(@SubjectCode, @SubjectName, @OfferedYear, @OfferedSemester, @LectureHours, @TuteHours, @LabHours, @EvolutionHours)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@SubjectCode", s.SubjectCode);
                cmd.Parameters.AddWithValue("@SubjectName", s.SubjectName);
                cmd.Parameters.AddWithValue("@OfferedYear", s.OfferedYear);
                cmd.Parameters.AddWithValue("@OfferedSemester", s.OfferedSemester);
                cmd.Parameters.AddWithValue("@LectureHours", s.LectureHours);
                cmd.Parameters.AddWithValue("@TuteHours", s.TuteHours);
                cmd.Parameters.AddWithValue("@LabHours", s.LabHours);
                cmd.Parameters.AddWithValue("@EvolutionHours", s.EvolutionHours);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Beispiel #3
0
        //delete
        public bool Delete(subjectClass s)
        {
            bool isSuccess = false;

            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //writing sql query
                string     sql = "DELETE FROM table_subject WHERE No=@No";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@No", s.No);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }


            return(isSuccess);
        }