/// <summary> /// 讀取注冊(cè)表,根據(jù)Office版本獲取數(shù)據(jù)庫(kù)連接字段 /// </summary> /// <returns>數(shù)據(jù)庫(kù)連接字段</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; }
更多信息請(qǐng)查看IT技術(shù)專欄