public List<DAO.MealEntry> getAllMealEntryInfo() { try { aSqlConnection.Open(); SqlCommand command = new SqlCommand("USPMealEntries", aSqlConnection); command.CommandType = CommandType.StoredProcedure; SqlDataReader aReader = command.ExecuteReader(); aMealEntryList = new List<MealEntry>(); if (aReader.HasRows) { while (aReader.Read()) { MealEntry aMealEntry=new MealEntry(); aMealEntry.memberId = (int)aReader[0]; aMealEntry.noOfMeals = Convert.ToInt32(aReader[1].ToString()); aMealEntry.mealEntryDate = (DateTime)aReader[2]; aMealEntryList.Add(aMealEntry); } } } catch (Exception e) { MessageBox.Show(e.Message); } finally { if (aSqlConnection != null && aSqlConnection.State == ConnectionState.Open) { aSqlConnection.Close(); } } return aMealEntryList; }
private void saveButton_Click(object sender, System.EventArgs e) { try { MealEntry aMealEntry = new MealEntry(Convert.ToInt32(memberIdComboBox.Text), Convert.ToInt32(noOfMealsComboBox.Text), dateTimePicker1.Value); string msg = aMealEntryBll.save(aMealEntry); MessageBox.Show(msg, @"Message"); showDataInDataGridView(); clearTextBoxes(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }