Using C# (VS2005) and Excel 2000

Posted on 2009-04-16
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
Question by:hoikar
    LVL 53

    Expert Comment

    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); 
    OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [Sheet1$]", objConn); 
    OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); 
    objAdapter1.SelectCommand = objCmdSelect; 
    DataSet objDataset1 = new DataSet(); 

    Open in new window


    Author Comment

    do I need to add any component or reference?
    LVL 53

    Expert Comment

    A reference to system.Data and System.Data.OleDb (both part of the .net framework)

    Author Comment

    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?
    LVL 53

    Accepted Solution

    Complete examples can be found here:

    Reading and Writing Excel using OLEDB

    Reading and Writing Excel Spreadsheets Using ADO.NET C# DbProviderFactory

    Reading and Writing Excel using OLEDB / Office Programming / C#

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    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.…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now