Esempio n. 1
0
        private void carregarDados()
        {
            conexao = new Conexao.Conexao();
            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();

            string connectionString = conexao.getConnectionString();
            string query            = "SELECT a.Contato,a.Email, a.Data_Nascimento, a.CPF, a.Nome, b.Bairro, b.Cidade, b.Rua, b.CEP, b.Numero, b.Id_Endereco, b.CPF from cliente a\n" +
                                      "\n" + "INNER JOIN endereco b ON b.CPF = a.CPF";

            using (MySqlConnection conn = new MySqlConnection(connectionString))


            {
                using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn))
                {
                    try
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            dataGridView1.Rows.Add(dataTable.Rows[i][4], dataTable.Rows[i][3], dataTable.Rows[i][2], dataTable.Rows[i][1], dataTable.Rows[i][0], dataTable.Rows[i][5], dataTable.Rows[i][6], dataTable.Rows[i][7], dataTable.Rows[i][8], dataTable.Rows[i][9], dataTable.Rows[i][10]);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erro: " + ex);
                    }
                }
            }
        }
Esempio n. 2
0
        private void carregarDados()
        {
            conexao = new Conexao.Conexao();
            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();

            string connectionString = conexao.getConnectionString();
            string query            = "SELECT a.Nome,a.Preco_Compra, a.Preco_Venda, a.Data_Vencimento, a.Quantidade_estoque, a.Codigo_Barras, b.TipoProduto, a.IdTipo from produto a\n" +
                                      "\n" + "INNER JOIN tipoproduto b ON b.IdTipo = a.IdTipo";

            using (MySqlConnection conn = new MySqlConnection(connectionString))


            {
                using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn))
                {
                    try
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        for (int i = 0; i < dataTable.Rows.Count; i++)
                        {
                            dataGridView1.Rows.Add(dataTable.Rows[i][0], dataTable.Rows[i][1], dataTable.Rows[i][2], dataTable.Rows[i][4], dataTable.Rows[i][5], dataTable.Rows[i][7], dataTable.Rows[i][6], dataTable.Rows[i][3]);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erro: " + ex);
                    }
                }
            }
        }