當(dāng)前位置:首頁 >  站長 >  數(shù)據(jù)庫 >  正文

讀取注冊表根據(jù)Office版本獲取數(shù)據(jù)庫連接字段

 2020-10-15 13:59  來源: 腳本之家   我來投稿 撤稿糾錯

  域名預(yù)訂/競價,好“米”不錯過

本節(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è)新機遇!

相關(guān)文章

熱門排行

信息推薦