短视频,自媒体,达人种草一站服务
本节主要介绍了如何根据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(@"SOFTWAREMicrosoftOffice11.0AccessInstallRoot"); //查询Office2007 RegistryKey f07 = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice12.0AccessInstallRoot"); //查询Office2010 RegistryKey f10 = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice14.0AccessInstallRoot"); 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; } (编辑:南平站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|