Пример #1
0
        public Clas GetClass(int cId)
        {
            conn.Open();
            string        query  = string.Format("SELECT * FROM Classes WHERE cId = '{0}'", cId);
            SqlCommand    cmd    = new SqlCommand(query, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            Clas          clas   = null;

            while (reader.Read())
            {
                clas          = new Clas();
                clas.cId      = reader.GetInt32(reader.GetOrdinal("cId"));
                clas.clas     = reader.GetInt32(reader.GetOrdinal("class"));
                clas.classFee = reader.GetInt32(reader.GetOrdinal("classFee"));
            }
            conn.Close();
            return(clas);
        }
Пример #2
0
 public bool UpdateClass(Clas c, int cId)
 {
     try
     {
         conn.Open();
         string     query = String.Format("UPDATE Classes SET class ='{0}', classFee = '{1}' WHERE cId = '{2}'", c.clas, c.classFee, cId);
         SqlCommand cmd   = new SqlCommand(query, conn);
         int        r     = cmd.ExecuteNonQuery();
         conn.Close();
         if (r > 0)
         {
             return(true);
         }
         return(false);
     }
     catch
     {
         MessageBox.Show("Update Class Failed, Class already exist");
         return(false);
     }
 }
Пример #3
0
 public bool AddClass(Clas c)
 {
     try
     {
         conn.Open();
         string     query  = String.Format("INSERT INTO Classes VALUES ('{0}','{1}')", c.clas, c.classFee);
         SqlCommand cmd    = new SqlCommand(query, conn);
         int        result = cmd.ExecuteNonQuery();
         conn.Close();
         if (result > 0)
         {
             return(true);
         }
         return(false);
     }
     catch
     {
         MessageBox.Show("Failed to add Class");
         return(false);
     }
 }