elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  Mostrar Mensajes
Páginas: [1]
1  Programación / Ejercicios / Ejercicio C# en: 20 Mayo 2019, 09:14 am
Hola, queria ver si alguien podria ayudarme a terminar este programa, se trata de importar dos archivos excel, ademas de mostrar su contenido en unos datagridview, y tambien, mostrar en un tercer datagridview, los registros que se repiten en la columna "telefono" de ambos archivos importados, considerando que si alguno se repite debe mostrarlo tambien, por el momento lo unico que parece me hace falta es la consulta en Linq, la cual me marca el error:

"No se encontro ninguna implementacion del patron de consulta para el tipo de origen datatable. No se encontro 'Join'." en el dt1 del query

Mi codigo actual es el siguiente:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.OleDb;

namespace Telefonos
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        DataTable dt1 = new DataTable();
        DataTable dt2 = new DataTable();
        DataTable query = new DataTable();

        private void btnSelect1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openfiledialog1 = new OpenFileDialog();
                openfiledialog1.Filter = "Excel Files | *.xlsx; *.xls; *.xlsm";

                if (openfiledialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.tBox1.Text = openfiledialog1.FileName;
                }

                string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + tBox1.Text + ";Extended Properties = \"Excel 12.0; HDR=YES;\" ; ";
                OleDbConnection con = new OleDbConnection(constr);
                con.Open();

                dropdown_sheet1.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                dropdown_sheet1.DisplayMember = "TABLE_NAME";
                dropdown_sheet1.ValueMember = "TABLE_NAME";
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnLoad1_Click(object sender, EventArgs e)
        {
            try
            {
                string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + tBox1.Text + ";Extended Properties = \"Excel 12.0; HDR=YES;\" ; ";
                OleDbConnection con = new OleDbConnection(constr);
                OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [" + dropdown_sheet1.SelectedValue + "]", con);
                sda.Fill(dt1);

                dataGridView1.DataSource = dt1;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnSelect2_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openfiledialog2 = new OpenFileDialog();
                openfiledialog2.Filter = "Excel Files | *.xlsx; *.xls; *.xlsm";

                if (openfiledialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.tBox2.Text = openfiledialog2.FileName;
                }

                string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + tBox2.Text + ";Extended Properties = \"Excel 12.0; HDR=YES;\" ; ";
                OleDbConnection con = new OleDbConnection(constr);
                con.Open();

                dropdown_sheet2.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                dropdown_sheet2.DisplayMember = "TABLE_NAME";
                dropdown_sheet2.ValueMember = "TABLE_NAME";
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnLoad2_Click(object sender, EventArgs e)
        {
            try
            {
                string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + tBox2.Text + ";Extended Properties = \"Excel 12.0; HDR=YES;\" ; ";
                OleDbConnection con = new OleDbConnection(constr);
                OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [" + dropdown_sheet2.SelectedValue + "]", con);
                sda.Fill(dt2);

                dataGridView2.DataSource = dt2;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnIntersect1_Click(object sender, EventArgs e)
        {
            try
            {
                query = from row1 in dt1
                        join row2 in dt2 on row1.TELEFONO equals row2.TELEFONO
                        select new
                        {
                            row1.FOLIO_FACTURA,
                            row1.CONCEPTO,
                            row1.FECHA_PUBLICACION,
                            row1.PERIODO,
                            row1.TELEFONO,
                            row1.MONTO,
                            row1.FECHA_MOVIMIENTO
                        };

                dataGridView3.DataSource = query;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

Cualquier detalle o recomendación se agradece  :)
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines