ASP.NET Core项目中缺少SqlDataAdapter [英] SqlDataAdapter missing in a ASP.NET Core project

查看:82
本文介绍了ASP.NET Core项目中缺少SqlDataAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在.NET Core 1.0项目中使用ADO.NET与没有实体框架的数据库建立连接.

I'm trying to get a connection to a database without Entity Framework, using ADO.NET in a .NET Core 1.0 project.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ASP_NETCore3.Models;
using System.Data;
using System.Data.SqlClient;
//using System.Configuration;

namespace ASP_NETCore3.Repository
{
    public class LineasRepository
    {
        private SqlConnection con;

        private void connection()
        {
            //TODO: Implementar variables de confuracion obtiendolas desde appsettings.json
            string constr = "Data Source=mylocaldb\\sql08;Initial Catalog=empresas;User id=user;Password=secret;Integrated Security=SSPI;";
            con = new SqlConnection(constr);
        }

        public List<LineasModel> GetAllLineas()
        {
            connection();
            List<LineasModel> LineasList = new List<LineasModel>();
            SqlCommand com = new SqlCommand("select * from CATLIN", con);
            com.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            con.Open();
            da.Fill(dt);
            con.Close();

            LineasList = (from DataRow dr in dt.Rows

                       select new LineasModel()
                       {
                           cod_lin = Convert.ToInt32(dr["COD_LIN"]),
                           nom_lin = Convert.ToString(dr["NOM_LIM"]),
                           margen = Convert.ToString(dr["MARGEN"]),
                       }).ToList();


            return EmpList;
        }
    }
}

如您所见,我可以使用System.Data.SqlClient,但是由于某种原因,编译器会说缺少SqlDataAdapter.

As you can see, I can use System.Data.SqlClient, but for some reason compiler says that SqlDataAdapter is missing.

我该怎么办?可以通过安装NuGet中的另一个软件包来修复它吗?

What can I do? It can be fixed installing another packages from NuGet?

推荐答案

.NET Core 2.0现在实现了SqlDataAdapter和DataTable.

.NET Core 2.0 now implements SqlDataAdapter and DataTable.

https://docs.microsoft.com/en-ca/dotnet/api/system.data.sqlclient.sqldataadapter?view=netcore-2.0

这篇关于ASP.NET Core项目中缺少SqlDataAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆