简体   繁体   English

使用 .net 内核将数据插入访问数据库

[英]inserting data into access database using .net core

I am trying to insert data to Access 365 in .net core API.我正在尝试将数据插入 .net 核心 API 中的 Access 365。 Below is what I did to insert the data, but I am getting an error saying that:以下是我插入数据的操作,但我收到一条错误消息:

The type or namespace name 'OleDbConnection' does not exist in the namespace 'System.Data.OleDb' (are you missing an assembly reference?)

I added the assembly reference to:我将程序集引用添加到:

    using System.Data;
    using System.Data.Odbc;
    using System.Data.OleDb

Below is my partial C# code:下面是我的部分 C# 代码:

  public void PrimeAccessRules()
        {
            List<RecLoad> recList = new List<RecLoad>();
            recList = getPrimeData();
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
        @"Data source= C:\Users\test\recload.accdb";

            try
            {
                conn.Open();
            }
        }

The error is coming right on this line:错误就在这一行:

System.Data.OleDb.**OleDbConnection**

saying that OleDbConnection does not exists说 OleDbConnection 不存在

Any help will be highly apprecaited.任何帮助都将受到高度赞赏。

The types in the System.Data.OleDb namespace are part of the System.Data assembly in .NET Framework, but they're not included in .NET Core or .NET Standard. System.Data.OleDb命名空间中的类型是 .NET 框架中System.Data程序集的一部分,但它们不包含在 .NET 核心或 .NET 标准中。 Since you're targetting one of the latter two (.NET Core), you'll need to add the System.Data.OleDb package to your project.由于您的目标是后两个 (.NET Core) 之一,因此您需要将System.Data.OleDb package 添加到您的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM