static  string connection;
        public void TestConnection(string dataFile)
        {
            connection = "Provider = Microsoft.ACE.OLEDB.12.0;Data source=" + dataFile;
            OleDbConnection oled = new OleDbConnection(connection);
            try
            {oled.Open();}
            catch
            {
                connection = "Provider = Microsoft.ACE.OLEDB.14.0;Data source=" + dataFile;
                oled.ConnectionString = connection;
                try
                {oled.Open();}
                catch { 
                    connection = "Provider = Microsoft.ACE.OLEDB.15.0;Data source=" + dataFile;
                    oled.ConnectionString = connection;
                    try
                    {oled.Open();}
                    catch
                    {
                        connection = "Provider = Microsoft.ACE.OLEDB.16.0;Data source=" + dataFile;
                        oled.ConnectionString = connection;
                        try
                        { oled.Open(); }
                        catch
                        {
                            connection = "Provider = Microsoft.JET.OLEDB.4.0; Data Source =" + dataFile;
                            oled.ConnectionString = connection;
                            try
                            { oled.Open(); }
                            catch
                            { System.Windows.MessageBox.Show("Err", "sonycat"); }
                        }
                    }
                }
            }
        }



        public string TestConnection(string dataFile)
        {
            string connection;
            connection = "Provider = Microsoft.ACE.OLEDB.12.0;Data source=" + dataFile;
            OleDbConnection oled = new OleDbConnection(connection);
            try
            { 
                oled.Open();
                return connection;
            }
            catch
            {
                connection = "Provider = Microsoft.ACE.OLEDB.14.0;Data source=" + dataFile;
                oled.ConnectionString = connection;
                try
                { 
                    oled.Open();
                    return connection;
                }
                catch
                {
                    connection = "Provider = Microsoft.ACE.OLEDB.15.0;Data source=" + dataFile;
                    oled.ConnectionString = connection;
                    try
                    { 
                        oled.Open();
                        return connection;
                    }
                    catch
                    {
                        connection = "Provider = Microsoft.ACE.OLEDB.16.0;Data source=" + dataFile;
                        oled.ConnectionString = connection;
                        try
                        {
                            oled.Open();
                            return connection;
                        }
                        catch
                        {
                            connection = "Provider = Microsoft.JET.OLEDB.4.0; Data Source =" + dataFile;
                            oled.ConnectionString = connection;
                            try
                            { 
                                oled.Open();
                                return connection;
                            }
                            catch
                            { 
                                System.Windows.MessageBox.Show("Err", "sonycat");
                                return connection;
                            }
                        }
                    }
                }
            }
        }

 

posted on 2023-10-09 14:16  sonycat  阅读(33)  评论(0编辑  收藏  举报