Zeb Muhammad

Zeb Muhammad

  • NA
  • 67
  • 18k

import Data from Excel to under The columns of DatagridView.

Aug 10 2017 4:07 AM
  1. Dear Friends
first I want to say thank you all , You have a stuning Job here.
Secondly,
I Want to Import Data from Excel File to My DataGrideview columns.
I tried but data coms after My added columns.Please, Check my code bellow.
  1. private void button8_Click_1(object sender, EventArgs e)
  2. {
  3. string content = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strExcelPathName.Text + "; Extended Properties=\"Excel 8.0;\";";
  4. OleDbConnection con = new OleDbConnection(content);
  5. OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM[" + txtSheet.Text + "$]", con);
  6. DataTable dt = new DataTable();
  7. oda.Fill(dt);
  8. dataGridView1.DataSource = dt;
  9. }
please, help me

Answers (3)