예제 #1
0
 public void AddSubject(SubjectDTO subjectDTO)
 {
     try
     {
         //insertion code
         connectionDB.OpenConnection();
         string sqlQuery = "insert into Subjects values('" + subjectDTO.CLASSNAME + "','" + subjectDTO.CLASSCODE + "','" + subjectDTO.SUBNAME + "','" + subjectDTO.SUBCODE + "')";
         connectionDB.ExecuteQueries(sqlQuery);
         connectionDB.CloseConnection();
         MessageBox.Show(" added Successfully!!");
     }
     catch (SqlException ex)
     {
         if (ex.Number > 0)
         {
             //Violation of primary key. Handle Exception
             connectionDB.CloseConnection();
             MessageBox.Show("Class Name or Class Code already exits. Try new one!", "Error..");
         }
     }
 }
예제 #2
0
 public void AddSubject(SubjectDTO subjectDTO)
 {
     try
     {
         //insertion code
         connectionDB.OpenConnection();
         string sqlQuery = "insert into Subjects values('" + subjectDTO.CLASSNAME + "','" + subjectDTO.CLASSCODE + "','" + subjectDTO.SUBNAME + "','" + subjectDTO.SUBCODE + "')";
         connectionDB.ExecuteQueries(sqlQuery);
         connectionDB.CloseConnection();
         MessageBox.Show("Subject added successfully to the database", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (SqlException ex)
     {
         if (ex.Number > 0)
         {
             //Violation of primary key. Handle Exception
             connectionDB.CloseConnection();
             MessageBox.Show("Subject Code already exists. \n Try a new code.", "Insertion Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }