[英]C# cannot find namespace OleDbConnection even though using System.Data.OleDb is there
I have one project (a web application), in production, where I have the following, which works, and then opened up another Visual Studio project (console application) and copy pasted the same code.我有一个项目(一个 Web 应用程序),在生产中,我有以下工作,然后打开另一个 Visual Studio 项目(控制台应用程序)并复制粘贴相同的代码。 The problem with the new project (console application) is that while the computer recognizes my namespace "System.Data.OleDb", VS is graying this out, and hovering over OleDbConnection gets the error message
新项目(控制台应用程序)的问题在于,当计算机识别出我的命名空间“System.Data.OleDb”时,VS 将其显示为灰色,将鼠标悬停在 OleDbConnection 上会收到错误消息
The type or namespace name "OleDbConnection not found (are you missing a using directive or an assembly reference?)
类型或命名空间名称“未找到 OleDbConnection(您是否缺少 using 指令或程序集引用?)
Since my using directive is there, I'm guessing it's the assembly reference, but when I go to Project --> add reference the only options are Projects, Shared Projects, and Browse, and for each of these three tabs there are 0 options to choose from.由于我的 using 指令在那里,我猜它是程序集引用,但是当我转到项目 --> 添加引用时,唯一的选项是项目、共享项目和浏览,并且对于这三个选项卡中的每一个都有 0 个选项从中选择。 How can I add this reference?
如何添加此引用?
My simple code is below我的简单代码如下
using System.Data;
using System.Data.OleDb;
public class DataLayer
{
public DataLayer()
{
}
static OleDbConnection conn;
// some other code below
}
In Visual Studio在 Visual Studio 中
It should be good after that之后应该就好了
You are missing the reference to System.Data, where this would be contained.您缺少对 System.Data 的引用,其中将包含该引用。 Ideally you should ensure it is checked under References, but apparently you tried that.
理想情况下,您应该确保在 References 下检查它,但显然您尝试过。
You could always just edit the project file and add it manually, eg您总是可以编辑项目文件并手动添加它,例如
The project needs a reference to System.Data.dll to be able to resolve.该项目需要对 System.Data.dll 的引用才能解析。 That dll can be located in the following directory (your use may vary based on framework, but pretty standard structure): C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.5.2.
该 dll 可以位于以下目录中(您的使用可能因框架而异,但非常标准的结构):C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.5.2。
You should have an assmeblies section in your "Add Reference" window, but you can add by browsing to the location as well.您应该在“添加参考”窗口中有一个组件部分,但您也可以通过浏览到该位置来添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.