-
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());
}
}
}
}
}
-
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***
-
Thanks
Nice article, thank you.
I've got it working now.
Pete