drupal stats

Import Excel file into DataGridView

July 8th, 2011 DataGridView 6 Comments


Import Excel file into DataGridView thumb Import Excel file into DataGridView

 

Import Excel file into DataGridView using C#

string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", txtPath.Text);

string query = String.Format("select * from [{0}$]", "Sheet1");

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);

DataSet dataSet = new DataSet();

dataAdapter.Fill(dataSet);

dataGridView1.DataSource = dataSet.Tables[0];

 

Download Source

Tags: import excel to datagridview in c#, import photo into wave file, Import Data from Excel to DataGridView in C#, import excel to datagridview, how to import excel file to datagridview in c#, c# excel to datagridview, import excel to datagridview c#, excel to datagridview c#, how to import data from excel to datagridview in c#, c# excel datagridview

Related posts:

  1. Import CSV file into DataGridView
  2. Export DataGridView to Excel
  3. Export DataGridView to XML using C#
  4. Export Data from DataGridView to CSV file
  5. Export GridView to Excel in ASP.NET

6 Comments

  1. Javed says:

    Thanks for
    Import Excel file into DataGridView this code help me

  2. makb says:

    this code helded me in importing excel xlsx file into datagrid but there is a problem, its ordering is different when it imports to data grid….

    anyone can tell me how i can import it in its original order???

  3. Warren says:

    Hi guys! any idea how to save back the data in the datagridview back to the excel file??

  4. mikelantzelo says:

    thank you!!!!very nice and easy!!!

  5. Nirosha says:

    Thanks Dear i was looking this its save my time

  6. Jignesh says:

    I can load the data but shows me an ” The ‘Microsoft.ACE.OLEDB.12.0′ provider is not registered on the local machine.” on dataAdapter.Fill(dataSet); …… InvalidOperation Exception was unhandled

    Please help out soon.