ADO .NET and Excel in C#

This is a discussion on ADO .NET and Excel in C# within the C# Programming forums, part of the General Programming Boards category; I'm having trouble loading Excel data into my application. Can anyone tell me what's wrong with the following method? My ...

  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 10: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, 07:04 AM
  2. Datagrid Export to MS Excel with C++ .NET
    By Gerudom in forum Windows Programming
    Replies: 3
    Last Post: 06-09-2006, 08:58 AM
  3. Exporting a DataTable to Excel (.NET)
    By Trauts in forum C# Programming
    Replies: 0
    Last Post: 07-29-2005, 02:03 PM
  4. C++ Builder and Excel files
    By mfdemi in forum Windows Programming
    Replies: 3
    Last Post: 09-24-2004, 02:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21