Exemplo n.º 1
0
        // method to read data from dataset
        public void Read()
        {
            // create table adapters for each table in the dataset
            ProjectTrackingDataSetTableAdapters.EmployeesTableAdapter taEmployees =
                new ProjectTrackingDataSetTableAdapters.EmployeesTableAdapter();
            ProjectTrackingDataSetTableAdapters.ProjectsTableAdapter taProjects =
                new ProjectTrackingDataSetTableAdapters.ProjectsTableAdapter();
            ProjectTrackingDataSetTableAdapters.StatusTableAdapter taStatus =
                new ProjectTrackingDataSetTableAdapters.StatusTableAdapter();
            ProjectTrackingDataSetTableAdapters.TasksTableAdapter taTasks =
                new ProjectTrackingDataSetTableAdapters.TasksTableAdapter();
            ProjectTrackingDataSetTableAdapters.WorkTableAdapter taWork =
                new ProjectTrackingDataSetTableAdapters.WorkTableAdapter();

            try
            {
                // load the data into the tables
                taEmployees.Fill(myProjects.Employees);
                taProjects.Fill(myProjects.Projects);
                taStatus.Fill(myProjects.Status);
                taTasks.Fill(myProjects.Tasks);
                taWork.Fill(myProjects.Work);
            }
            catch (Exception ex)
            {
                SetReadyLabel("Error loading data from database");
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        // method to save data to dataset
        public void Save()
        {
            // create table adapters for each table in the dataset
            ProjectTrackingDataSetTableAdapters.EmployeesTableAdapter taEmployees =
                new ProjectTrackingDataSetTableAdapters.EmployeesTableAdapter();
            ProjectTrackingDataSetTableAdapters.ProjectsTableAdapter taProjects =
                new ProjectTrackingDataSetTableAdapters.ProjectsTableAdapter();
            ProjectTrackingDataSetTableAdapters.StatusTableAdapter taStatus =
                new ProjectTrackingDataSetTableAdapters.StatusTableAdapter();
            ProjectTrackingDataSetTableAdapters.TasksTableAdapter taTasks =
                new ProjectTrackingDataSetTableAdapters.TasksTableAdapter();
            ProjectTrackingDataSetTableAdapters.WorkTableAdapter taWork =
                new ProjectTrackingDataSetTableAdapters.WorkTableAdapter();

            // create instance of table adapter manager to manage all tables
            ProjectTrackingDataSetTableAdapters.TableAdapterManager taManager =
                new ProjectTrackingDataSetTableAdapters.TableAdapterManager();

            // assign each table table adapter to the table adapter manager
            taManager.EmployeesTableAdapter = taEmployees;
            taManager.ProjectsTableAdapter  = taProjects;
            taManager.StatusTableAdapter    = taStatus;
            taManager.TasksTableAdapter     = taTasks;
            taManager.WorkTableAdapter      = taWork;

            try
            {
                // using manager, update all of the tables
                taManager.UpdateAll(myProjects);
            }
            catch (Exception ex)
            {
                SetReadyLabel("Error saving to database");
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }