コード例 #1
0
        private void sector_Load(object sender, EventArgs e)
        {
            try
            {
                comboBoxSector.Items.Clear();
                string sqlQuery = "Select name FROM sector";
                connectionDB.PutQueryIntoComboBox(sqlQuery, comboBoxSector, "name");

                if (dataGridViewSector.ColumnCount != 0)
                {
                    ds.Tables["bddmontijotest"].Columns.Clear(); // Clear column of database
                    ds.Tables["bddmontijotest"].Rows.Clear();    // Clear Rows of database
                }
                dataGridViewSector.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                string sqlCommand = "SELECT * FROM sector";
                dataAdapter = new MySqlDataAdapter(sqlCommand, connectionDB.getMyconnectionString());
                // 3. fill in insert, update, and delete commands
                MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(dataAdapter);

                dataAdapter.Fill(ds, "bddmontijotest");
                dataGridViewSector.DataSource = ds;                                       // Fill the dataGridViewList
                dataGridViewSector.DataMember = "bddmontijotest";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            connectionDB.ConnectionMySql();
            comboBoxCompany.Items.Clear();


            string sqlCommand = "SELECT DISTINCT name FROM company";

            connectionDB.PutQueryIntoComboBox(sqlCommand, comboBoxCompany, "name"); // Use method to add the query into the comboBoxCompany

            if (dataGridViewList.ColumnCount != 0)
            {
                ds.Tables["dbepm"].Columns.Clear(); // Clear column of database
                ds.Tables["dbepm"].Rows.Clear();    // Clear Rows of database
            }

            try
            {
                sqlCommand  = "SELECT l.* FROM " + comboBoxList.Text + " l JOIN company c ON c.id = l.idCompany";
                dataAdapter = new MySqlDataAdapter(sqlCommand, connectionDB.getMyconnectionString());
                // 3. fill in insert, update, and delete commands
                MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(dataAdapter);
                dataAdapter.Fill(ds, "dbepm");
                dataGridViewList.DataSource = ds;                                       // Fill the dataGridViewList
                dataGridViewList.DataMember = "dbepm";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        private void CompanyListForm_Load(object sender, EventArgs e)
        {
            connectionDB.ConnectionMySql();
            dataGridViewCompanies.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            comboBoxSector.Items.Clear();
            comboBoxSector.Items.Add("All companies");

            comboBoxCompany.Items.Clear();
            comboBoxEmail.Items.Clear();


            ds.Clear();


            try
            {
                string sqlQuery = "SELECT DISTINCT name FROM company";
                connectionDB.PutQueryIntoComboBox(sqlQuery, comboBoxCompany, "name");

                string sqlCommand = "SELECT name FROM sector";
                connectionDB.PutQueryIntoComboBox(sqlCommand, comboBoxSector, "name");

                sqlCommand  = "SELECT * FROM company ORDER BY name";
                dataAdapter = new MySqlDataAdapter(sqlCommand, connectionDB.getMyconnectionString());
                // 3. fill in insert, update, and delete commands
                MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(dataAdapter);
                dataAdapter.Fill(ds, "bddmontijotest");
                dataGridViewCompanies.DataSource = ds;
                dataGridViewCompanies.DataMember = "bddmontijotest";
            }
            catch (Exception)
            {
                throw;
            }
        }