读取注册表根据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; }