0

Using breakpoints I found that the problem starts when the searching process reaches dAdapter.Fill(ds);. The exception is "Couldn't find install-able ISAM".

function starts here
{
    try
    {
        string startPath = directorytbx.Text.ToString() + @":\Windows Data Management System\";
        // string[] oDirectories = Directory.GetDirectories(startPath, nametbx.Text + ".xls", SearchOption.AllDirectories);
        DirectoryInfo info = new DirectoryInfo(startPath);
        DirectoryInfo[] arry = info.GetDirectories();
        List<string> listOfFolderNames = new List<string>();
        foreach (DirectoryInfo dInfo in arry)
        {
            listOfFolderNames.Add(dInfo.Name);
        }
        List<string> finalPaths = new List<string>();
        foreach (string checker in listOfFolderNames)
        {
            if (checker.ToUpper().Contains(nametbx.Text.ToUpper()))
            {
                finalPaths.Add(checker);
            }
        }
        int i = 0;
        foreach (DirectoryInfo dInfo in arry)
        {
            DirectoryInfo dsubInfo = new DirectoryInfo(dInfo.FullName + "\\");
            FileInfo[] dsubInfoArray = dsubInfo.GetFiles();

            String name = dsubInfo + "\'" + dsubInfoArray[1].ToString();

            //String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +dsubInfoArray + ";Extended Properties='Excel 12.0 XML;HDR=YES;';";

            //string PathConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dsubInfoArray + ";Extended Properties='Excel 12.0 XML;HDR=YES;';";

            //create the "database" connection string 
            string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + name + ";Excel 12.0 Xml;HDR=YES";

            //create the database query
            string query = "SELECT * FROM [Sheet1$]";

            //create an OleDbDataAdapter to execute the query
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
            DataSet ds = new DataSet();
            dAdapter.Fill(ds);
            //fill the DataTable
            DataTable data = ds.Tables[0];
            dAdapter.Fill(data);
            dataGridView1.DataSource = data;
            dAdapter.Dispose();

            i++;
        }
    }
    catch (Exception ex)
    {
        errlbl.Show();
        errlbl.Text = "Error: " + ex.Message;
    }
}
4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.