943,670 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 15647
  • C# RSS
Jun 19th, 2008
0

Read Data From MS Excel 2007

Expand Post »
hi everybody,

i want to read data from Ms Excel 2007 . So i used this connection string

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;"+"Data Source="+txtFilepath.Text+";"+"Extended Properties=Excel 12.0;";

but it display error :Could not find installable ISAM.

i also installed AccessdabaseEngine.exe

but still display the same error.

please help me
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
senpark15 is offline Offline
4 posts
since Apr 2008
Oct 30th, 2008
0

Re: Read Data From MS Excel 2007

Dear Senpark,

I know its very late to reply this post. But i think it will really helpful to you.

C# Syntax (Toggle Plain Text)
  1.  
  2. string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;
  3. Data Source=C:\Members.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""";
  4.  
  5. // if you don't want to show the header row (first row)
  6. // use 'HDR=NO' in the string
  7.  
  8. string strSQL = "SELECT * FROM [Sheet1$]";
  9.  
  10. OleDbConnection excelConnection = new OleDbConnection(connectionString);
  11. excelConnection.Open(); // This code will open excel file.
  12.  
  13. OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection);
  14. OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand);
  15.  
  16. // create data table
  17. DataTable dTable = new DataTable();
  18. dataAdapter.Fill(dTable);
  19.  
  20. // bind the datasource
  21. dataBingingSrc.DataSource = dTable;
  22.  
  23. // assign the dataBindingSrc to the DataGridView
  24. dgvExcelList.DataSource = dataBingingSrc;
  25.  
  26. // dispose used objects
  27. dTable.Dispose();
  28. dataAdapter.Dispose();
  29. dbCommand.Dispose();
  30.  
  31. excelConnection.Close();
  32. excelConnection.Dispose();
Last edited by cscgal; Oct 30th, 2008 at 8:52 pm. Reason: Fixed broken code tags
Reputation Points: 10
Solved Threads: 1
Newbie Poster
vimalfor5 is offline Offline
10 posts
since Sep 2007
Feb 10th, 2010
0
Re: Read Data From MS Excel 2007
Thanks Vimalfor5,
Your code is very helpful for me.
Thanks a lot!
Last edited by crystallove; Feb 10th, 2010 at 3:22 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crystallove is offline Offline
1 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: STRUCT and object memory addressing
Next Thread in C# Forum Timeline: Store XML File in SQL Data Base





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC