Hi All,
I am trying to use the following code (from another post) to import excel into my application and then dislplay the results in a dataGridview
private void button1_Click(object sender, EventArgs e)
{
DataTable test = getDataFromXLS("c:\temp.xls");
if (test != null)
dataGridView1.DataSource = test;
}
{
try
{
string strConnectionString = "";
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + strFilePath + "; Jet OLEDB:Engine Type=5;" +
"Extended Properties=Excel 8.0;";
OleDbConnection cnCSV = new OleDbConnection(strConnectionString);
cnCSV.Open();
OleDbCommand cmdSelect = new OleDbCommand(@"SELECT * FROM [Sheet1$]", cnCSV);
OleDbDataAdapter daCSV = new OleDbDataAdapter(); daCSV.SelectCommand = cmdSelect;
DataTable dtCSV = new DataTable();
daCSV.Fill(dtCSV);
cnCSV.Close();
daCSV = null;
return dtCSV;
}
catch (Exception ex)
{
return null;
}
finally { }
}
My problem is, it is doing absolutely nothing .. no errors no nothing ...
Do I need to register/enable OLEDB on my local machine Or is this included/enabled in the .Net framework...
any suggestions would be greatly appreciated...
thanks,
Paul