Excel.Application ExcelApp = new Excel.ApplicationClass();
ExcelApp.Visible = false;
String WorkbookPath = filename;
Excel.Workbook ExcelWorkbook = ExcelApp.Workbooks.Open(WorkbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Worksheet Sheet = (Excel.Worksheet)ExcelWorkbook.Sheets[1];
DataTable newTable = new DataTable();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties= Excel 8.0";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + Sheet + "$]", conn);
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(newTable);
dataGridView1.DataSource = newTable;
I am using this code to read an excel file and save the data in a datatable ....
I am getting this error "System.__ComObject$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long." and the error pointer comes on the second last line of the code
can neone help ... its real urgent