Beispiel #1
0
        public static string GetConnectionString(OledDbDriverName driverName, ExtendedProperties extenProps, string filePath)
        {
            Dictionary <string, string> props = new Dictionary <string, string>();

            // XLSX - Excel 2007, 2010, 2012, 2013
            props["Provider"]            = GetDriverName(driverName);
            props["Extended Properties"] = extenProps.GetStringValue();
            props["Data Source"]         = filePath;

            // XLS - Excel 2003 and Older
            //props["Provider"] = "Microsoft.Jet.OLEDB.4.0";
            //props["Extended Properties"] = "Excel 8.0";
            //props["Data Source"] = "C:\\MyExcel.xls";

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> prop in props)
            {
                sb.Append(prop.Key);
                sb.Append('=');
                sb.Append(prop.Value);
                sb.Append(';');
            }

            return(sb.ToString());
        }