讀取注冊表依據Office版本獲取數據庫銜接字段。本站提示廣大學習愛好者:(讀取注冊表依據Office版本獲取數據庫銜接字段)文章只能為提供參考,不一定能成為您想要的結果。以下是讀取注冊表依據Office版本獲取數據庫銜接字段正文
/// <summary> /// 讀取注冊表,依據Office版本獲取數據庫銜接字段 /// </summary> /// <returns>數據庫銜接字段</returns> private string GetConnectionString() { string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "; RegistryKey rk = Registry.LocalMachine; //查詢Office2003 RegistryKey f03 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Access\InstallRoot\"); //查詢Office2007 RegistryKey f07 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Access\InstallRoot\"); //查詢Office2010 RegistryKey f10 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Access\InstallRoot\"); if (f03 != null) { strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = "; } else if (f07 != null || f10 != null) { strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = "; } return strConnectionString; }