public static void InputUserFromExcel(string filePath) { string FileExName = filePath.Substring(filePath.LastIndexOf(".") + 1); string mystring = "Provider = Microsoft.ACE.OLEDB.12.0 ; Data Source ='" + filePath + "';Extended Properties ='Excel 12.0;HDR=YES;IMEX=1'"; if (FileExName == "xls") { mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source ='" + filePath + "';Extended Properties=Excel 8.0"; } OleDbConnection cnnxls = new OleDbConnection(mystring); cnnxls.Open(); OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [pos_260$]", cnnxls); DataSet ZLDs = new DataSet(); myDa.Fill(ZLDs); Console.Write(ZLDs.Tables[0].Rows.Count); Console.Read(); } }