Problem Reading Excel File ?
-
Hi , I am trying to read an MS Excel file in my C# class. But problem is its not showing me the column values. I have checked in actual excel file , those columns do contain values but due to some reason my code is not reading it. here is what i m doing : Code Blockstring filename = "xmp.xls;"; strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source= " + filename + "Extended Properties=Excel 8.0;"; OleDbConnection ObjConn = new OleDbConnection(strConn); ObjConn.Open(); object[] objArrRestrict; objArrRestrict = new object[] {null, null, null, "TABLE"}; DataTable schemaTbl; schemaTbl = ObjConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,objArrRestrict); Hashtable ht = new Hashtable(); int index = 0; foreach (DataRow row in schemaTbl.Rows) { ht.Add( index, row["TABLEX] ); index++; } string sheetName = (string)ht[0]; OleDbCommand ObjCmd = new OleDbCommand( "SELECT * FROM [" + sheetName + "]", ObjConn); OleDbDataAdapter objDA = new OleDbDataAdapter(); objDA.SelectCommand = ObjCmd; objDA.Fill(recordsDT); ObjConn.Close(); DataRow rowx= recordsDT.Rows[14]; // and now if i try to read value of 6th column rowx[5].ToString(); // gives empty string rowx["6th Col"].ToString(); // it returns me empty string and actually this column do contain value and similary i can't get values of col 7,8 but I do get the values of Col 1-5 and after Col 9. But if I try to same column values of row 1,2 it works fine. It starts to get funny after row no 7. ( each row contains 80 coumns) Thanks ZINK