01 /// <summary>
02 /// 读取注册表,根据Office版本获取数据库连接字段
03 /// </summary>
04 /// <returns>数据库连接字段</returns>
05 private string GetConnectionString()
06 {
07 string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = ";
08
09 RegistryKey rk = Registry.LocalMachine;
10 //查询Office2003
11 RegistryKey f03 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Access\InstallRoot\");
12 //查询Office2007
13 RegistryKey f07 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Access\InstallRoot\");
14 //查询Office2010
15 RegistryKey f10 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Access\InstallRoot\");
16
17 if (f03 != null)
18 {
19 strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = ";
20 }
21 else if (f07 != null || f10 != null)
22 {
23 strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = ";
24 }
25
26 return strConnectionString;
27 }
中国足彩网信息请查看IT技术专栏
2025国考·省考课程试听报名