Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to show data from ms excel 2007 in datagridview in c# visual studio 2008

What I have tried:

System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection(@"provider=Microsoft.ACE.OLEDB.12.0;Data Source='c:\Book1.xlsx';Extended Properties=Excel 12.0 Xml;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Book1]", MyConnection);

MyCommand.TableMappings.Add("Table", "Net-informations.com");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
MyConnection.Close();
Posted
Updated 19-Feb-16 23:54pm
Comments
OriginalGriff 20-Feb-16 5:01am    
And?
What happens that you didn't expect, or doesn't happen that you did?
In fact, what happens at all! :laugh:
Greg Barbados 4-Mar-16 2:16am    
See this: https://janewdaisy.wordpress.com/2011/11/29/c-export-data-from-excel-to-datatable/

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900