本節(jié)主要介紹了如何根據(jù)Office版本獲取數(shù)據(jù)庫連接字段,以讀取注冊表獲取Office版本,實現(xiàn)代碼如下,感興趣的朋友不要錯過
///
/// 讀取注冊表,根據(jù)Office版本獲取數(shù)據(jù)庫連接字段
///
/// 數(shù)據(jù)庫連接字段
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;
}
本文來自腳本之家,原文鏈接:https://www.jb51.net/article/52701.htm
申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點子。點擊此處,共同探討創(chuàng)業(yè)新機遇!