Thread: ADO .NET and Excel in C#

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    Gloucester, England
    Posts
    11

    Post ADO .NET and Excel in C#

    I'm having trouble loading Excel data into my application. Can anyone tell me what's wrong with the following method?

    My connectionString is:

    Code:
    private static string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
                                               Data Source=C:\RD.xls;
                                               Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";";
    Code:
            private void ReadExcelData()
            {
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    using (OleDbCommand command = new OleDbCommand("SELECT * FROM [Questions$]"))
                    {
                        connection.Open();
                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Console.WriteLine(reader[0].ToString());
                            }
                        }
                    }
                }
            }

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    I've never use ado with Excel but with Access plenty of times, which I imagine is similar. Anyway, [removed], (though I am fairly new to c# ) but anyway here is a good example to look at check this out, http://blog.lab49.com/?p=196

    *** I looked up using***
    Last edited by Darryl; 09-13-2007 at 09:00 AM.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    Gloucester, England
    Posts
    11

    Thanks

    Nice article, thank you.

    I've got it working now.

    Pete

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Excel dependent on .Net Framework Runtime?
    By George2 in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 06:04 AM
  2. Datagrid Export to MS Excel with C++ .NET
    By Gerudom in forum Windows Programming
    Replies: 3
    Last Post: 06-09-2006, 07:58 AM
  3. Exporting a DataTable to Excel (.NET)
    By Trauts in forum C# Programming
    Replies: 0
    Last Post: 07-29-2005, 01:03 PM
  4. C++ Builder and Excel files
    By mfdemi in forum Windows Programming
    Replies: 3
    Last Post: 09-24-2004, 01:51 AM