域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過
本節(jié)主要介紹了如何根據(jù)Office版本獲取數(shù)據(jù)庫(kù)連接字段,以讀取注冊(cè)表獲取Office版本,實(shí)現(xiàn)代碼如下,感興趣的朋友不要錯(cuò)過
///
/// 讀取注冊(cè)表,根據(jù)Office版本獲取數(shù)據(jù)庫(kù)連接字段
///
/// 數(shù)據(jù)庫(kù)連接字段
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
申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!