简体   繁体   English

即使使用 System.Data.OleDb,C# 也找不到命名空间 OleDbConnection

[英]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 中

  • Navigate to the Tools Tab导航到工具选项卡
  • Click NuGet Packet Manager单击 NuGet 数据包管理器
    • Click Nuget Packet Manager Console // A command-line console should pop up at the bottom of Visual Studio单击 Nuget Packet Manager Console // 应在 Visual Studio 底部弹出命令行控制台
    • Insert the following command插入以下命令
    • Install-Package System.Data.OleDb安装包 System.Data.OleDb

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.

相关问题 在代码中使用System.Data.OleDb命名空间时找不到OleDbConnection - OleDbConnection not found while using System.Data.OleDb namespace in code C#使用System.Data.OleDb的问题 - C # using System.Data.OleDb problem C#WebApplication-找到System.Data.OleDb但几乎为空 - C# WebApplication - System.Data.OleDb found but nearly empty Vidual Studio 2017 C# System.Data.OleDb 无法读取较新的 Excel 文件 - Vidual Studio 2017 C# System.Data.OleDb cannot read newer Excel files 使用C#,是否可以使System.Data.OleDb处理特殊字符? - Using C#, is it possible to make System.Data.OleDb handle special characters? 在命名空间“System.Data.OleDb”中找不到类型名称“OleDbDataAdapter” - Type name "OleDbDataAdapter" could not be found in the namespace "System.Data.OleDb" Xamarin的System.Data.dll 2.0.5.0的System.Data.OleDb中缺少OleDbConnection - OleDbConnection missing in System.Data.OleDb on System.Data.dll 2.0.5.0 for Xamarin System.Data.OleDb替代System.Data.OracleClient(C#) - System.Data.OleDb as alternative to System.Data.OracleClient (C#) PlatformNotSupportedException:此平台不支持 System.Data.OleDb - PlatformNotSupportedException: System.Data.OleDb is not supported on this platform System.Data.OleDB “条件表达式中的数据类型不匹配。” - System.Data.OleDB 'Data type mismatch in criteria expression.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM