?
Solved

Using C# (VS2005) and Excel 2000

Posted on 2009-04-16
5
Medium Priority
?
396 Views
Last Modified: 2013-12-17
Anyone could send me a sample using OLEDB to read and write excel (2000) file using c# (2005)

BTW, I have installed the PIAsfor Office XP, is there any impact? and does anyone know how to remove these
(Install using gacutil and regedit, so I cannot delete this using Add/Remove Program)

Many Thanks
0
Comment
Question by:hoikar
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24155858
This approach is extremely useful when you need to read the  data from an Excel file fast and store the data in a DataTable for further usage.
using System.Data; 
using System.Data.OleDb; 
  
...  
  
String sConnectionString =  
"Provider=Microsoft.Jet.OLEDB.4.0;" + 
"Data Source=" + [Your Excel File Name Here] + ";" + 
"Extended Properties=Excel 8.0;"; 
  
 
OleDbConnection objConn = new OleDbConnection(sConnectionString); 
  
objConn.Open(); 
  
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]", objConn); 
  
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); 
  
objAdapter1.SelectCommand = objCmdSelect; 
  
DataSet objDataset1 = new DataSet(); 
  
objAdapter1.Fill(objDataset1); 
  
objConn.Close(); 
  

Open in new window

0
 

Author Comment

by:hoikar
ID: 24156043
do I need to add any component or reference?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24156053
A reference to system.Data and System.Data.OleDb (both part of the .net framework)
0
 

Author Comment

by:hoikar
ID: 24156076
As mention in the question, how to read and write?
Do I need to create  component - objAdapter1 for reading data

can you send me a sample project file for reference?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 1000 total points
ID: 24156105
Complete examples can be found here:

Reading and Writing Excel using OLEDB
http://www.codeproject.com/KB/office/excel_using_oledb.aspx

Reading and Writing Excel Spreadsheets Using ADO.NET C# DbProviderFactory
http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx

Reading and Writing Excel using OLEDB / Office Programming / C#
http://netcode.ru/dotnet/?lang=&katID=30&skatID=267&artID=7351
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question