Beispiel #1
0
        //Methord to Update record in database from app
        public bool updateSubject(ClassSubject s)
        {
            //Creating a deult return type and setting its value to false
            bool isSuccess = false;

            //Database Connection
            SqlConnection con = new SqlConnection(myconstr);

            try
            {
                //Update query
                String sql = "UPDATE Subject SET SubjectCode=@txtSubCode,SubjectName=@txtSubName,OfferedYear=@txtOffYear,OfferedSem=@drpOffSem,NumLecHr=@NumLecHr,NumTuteHr=@NumTuteHr,NumLabHr=@NumLabHr,NumEveHr=@NumEveHr WHERE Id=@txtId";

                SqlCommand cmd = new SqlCommand(sql, con);

                //Create parameter to ad data
                cmd.Parameters.AddWithValue("@txtId", s.ID);
                cmd.Parameters.AddWithValue("@txtOffYear", s.OfferYear);
                cmd.Parameters.AddWithValue("@drpOffSem", s.OfferSemester);
                cmd.Parameters.AddWithValue("@txtSubCode", s.SubCode);
                cmd.Parameters.AddWithValue("@txtSubName", s.SubName);
                cmd.Parameters.AddWithValue("@NumLecHr", s.NumLecHr);
                cmd.Parameters.AddWithValue("@NumTuteHr", s.NumTuteHr);
                cmd.Parameters.AddWithValue("@NumLabHr", s.NumLabHr);
                cmd.Parameters.AddWithValue("@NumEveHr", s.NumEveHr);

                //MessageBox.Show("" + s.ID + s.OfferYear + s.OfferSemester + s.SubName + s.SubCode + s.NumLecHr + s.NumTuteHr + s.NumLabHr + s.NumEveHr + "Update Called", "Informtion", MessageBoxButtons.OK, MessageBoxIcon.Error);


                con.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                con.Close();
            }
            return(isSuccess);
        }
Beispiel #2
0
        public bool insertSubject(ClassSubject s)
        {
            //Creating a deult return type and setting its value to false
            bool isSuccess = false;
            //Database Connection
            SqlConnection con = new SqlConnection(myconstr);

            try
            {
                //Insert query
                String sql2 = "INSERT INTO Subject (SubjectCode,SubjectName,OfferedYear,OfferedSem,NumLecHr,NumTuteHr,NumLabHr,NumEveHr) VALUES (@txtSubCode,@txtSubName,@txtOffYear,@drpOffSem,@NumLecHr,@NumTuteHr,@NumLabHr,@NumEveHr)";

                SqlCommand cmd2 = new SqlCommand(sql2, con);

                //Create parameter to ad data
                cmd2.Parameters.AddWithValue("@txtOffYear", s.OfferYear);
                cmd2.Parameters.AddWithValue("@drpOffSem", s.OfferSemester);
                cmd2.Parameters.AddWithValue("@txtSubCode", s.SubCode);
                cmd2.Parameters.AddWithValue("@txtSubName", s.SubName);
                cmd2.Parameters.AddWithValue("@NumLecHr", s.NumLecHr);
                cmd2.Parameters.AddWithValue("@NumTuteHr", s.NumTuteHr);
                cmd2.Parameters.AddWithValue("@NumLabHr", s.NumLabHr);
                cmd2.Parameters.AddWithValue("@NumEveHr", s.NumEveHr);

                con.Open();

                int rows2 = cmd2.ExecuteNonQuery();

                if (rows2 > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                con.Close();
            }
            return(isSuccess);
        }