public void New() { try { var adm=Convert.ToInt32(AdmNo); var fdataset = new financeapplicationDataSet(); var sdetailsAdapter = new financeapplicationDataSetTableAdapters.students_detailsTableAdapter(); var pdetailsAdapter = new financeapplicationDataSetTableAdapters.payment_detailsTableAdapter(); try { sdetailsAdapter.Insert(Convert.ToInt32(_admNo), _firstName, _lastName, _dofBirth, _gender, _admDate, _parentName, _parentContact); //loop to initialize payment details of the new student from form 1-4 to 0 in db for (var count1 = 1; count1 < 5; count1++) { for (var count2 = 1; count2 < 4; count2++) { pdetailsAdapter.Insert(Convert.ToInt32(_admNo), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, count1, count2, 0); } } MessageBox.Show("The Student " + _firstName + " has been added to the database"); var stv = new StudentView(); stv.PageClear(); } catch (Exception e2) { MessageBox.Show("An error has occured. Error Message: " + e2.Message.ToString()); } } catch(Exception e1) { MessageBox.Show("Error occured while trying to write to the database. Please try again. Error Message: "+ e1.Message.ToString()); } }
internal void Modify() { try { var adm = Convert.ToInt32(AdmNo); var fdataset = new financeapplicationDataSet(); var fdatasetadapter = new financeapplicationDataSetTableAdapters.students_detailsTableAdapter(); fdatasetadapter.Fill(fdataset.students_details); var sqlwhere = "admission_no=" + adm; var newDataTable = fdataset.students_details.Select(sqlwhere).CopyToDataTable(); var row = newDataTable.Rows[0]; try { MessageBox.Show((Convert.ToInt32(row[0].ToString())).ToString()); //fdatasetadapter.Update(Convert.ToInt32(admNo), firstName, lastName, dofBirth, gender, admDate, parentName, parentContact); MessageBox.Show("The Student " + row[0].ToString() + " has been added to the database"); var stv = new StudentView(); stv.PageClear(); } catch (Exception e2) { MessageBox.Show("An error has occured. Error Message: " + e2.Message.ToString()); } } catch (Exception e1) { MessageBox.Show("Error occured while trying to write to the database. Please try again. Error Message: " + e1.Message.ToString()); } }