富贵资源网 Design By www.hznty.com
/// <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(@"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; 
}
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com