读取注册表根据Office版本获取数据库连接字段
程序员文章站
2022-03-09 08:11:12
/// /// 读取注册表,根据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; }
上一篇: 四种数据库随机获取10条数据的方法
下一篇: 基于Python实现简单的人脸识别系统