欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

读取注册表根据Office版本获取数据库连接字段

程序员文章站 2023-12-29 15:51:04
/// /// 读取注册表,根据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(@"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; 
}

上一篇:

下一篇: