Как выполнить внутреннее соединение после импорта excel в новый gridview без базы данных
у меня есть 3 gridview , 2 для импорта excel и 1 для внутреннего соединения
2 gridview для импорта сделан , но для внутреннего соединения еще нет , может мне помочь
спасибо
Что я уже пробовал:
public partial class Form1 : Form { public DataTable ReadExcel(string fileName, string fileExt) { string conn = string.Empty; DataTable dtexcel = new DataTable(); if (fileExt.CompareTo(".xls") == 0) conn = @"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HRD=NO;IMEX=1';"; //for below excel 2007 else conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=NO';"; //for above excel 2007 using (OleDbConnection con = new OleDbConnection(conn)) { try { OleDbDataAdapter oleAdpt = new OleDbDataAdapter("select * from [Sheet1$]", con); //here we read data from sheet1 oleAdpt.Fill(dtexcel); //fill excel data into dataTable } catch { } } return dtexcel; } public Form1() { InitializeComponent(); // BindGrid(); } private void button1_Click(object sender, EventArgs e) { string filePath = string.Empty; string fileExt = string.Empty; OpenFileDialog file = new OpenFileDialog(); //open dialog to choose file if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user { this.richTextBox1.Text = file.FileName; filePath = file.FileName; //get the path of the file fileExt = Path.GetExtension(filePath); //get the file extension if (fileExt.CompareTo(".xls") == 0 || fileExt.CompareTo(".xlsx") == 0) { try { DataTable dtExcel = new DataTable(); dtExcel = ReadExcel(filePath, fileExt); //read excel file dataGridView1.Visible = true; dataGridView1.DataSource = dtExcel; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } else { MessageBox.Show("format file harus .xls atau .xlsx .", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); //custom messageBox to show error } } } private void button3_Click(object sender, EventArgs e) { string filePath = string.Empty; string fileExt = string.Empty; OpenFileDialog file = new OpenFileDialog(); //open dialog to choose file if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK) //if there is a file choosen by the user { this.richTextBox2.Text = file.FileName; filePath = file.FileName; //get the path of the file fileExt = Path.GetExtension(filePath); //get the file extension if (fileExt.CompareTo(".xls") == 0 || fileExt.CompareTo(".xlsx") == 0) { try { DataTable dtExcel = new DataTable(); dtExcel = ReadExcel(filePath, fileExt); //read excel file dataGridView2.Visible = true; dataGridView2.DataSource = dtExcel; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } else { MessageBox.Show("format file harus .xls atau .xlsx .", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); //custom messageBox to show error } } }