SqlDataAdapter is missing from ASP.NET Core project
I am trying to get a database connection 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;
}
}
}
As you can see, I can use System.Data.SqlClient, but for some reason the compiler says the SqlDataAdapter is missing.
What can I do? Can I install other packages from NuGet?
source to share
.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
source to share
It looks like the .net core does not provide implementations for SqlDataAdapter
and evenDataTable
This is a quote from this page
Relatively
DataTable and DataSet and SqlDataAdapter not found ...?!?
as for .NET Core 1.0 data access technologies> limited to low-level ADO.NET interfaces (IDbConnection, IDbCommand, etc.) or rich EF Core. > However, you can use third party libraries that can be used as replacements for DataRow / DataTable / DataAdapter, such as NReco.Data .
source to share
I have recompiled MySQL.Data for .net core 2.0 with mysql dataadapter and collector compiled to. I have tested so far.
https://github.com/amjtech/MySQL.Data
Enjoy.
source to share