本文介绍了在.NET Core中使用DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server中有一个存储过程,该存储过程接受用户定义的表类型。我正在关注这篇帖子的答案有关如何将DataTable发送到SQL中的存储过程。

I have a stored procedure in SQL Server that accepts a User-Defined Table Type. I'm following the answer from this post Bulk insert from C# list into SQL Server into multiple tables with foreign key constaints on how to send a DataTable to a stored procedure in SQL.

但是当我创建 DataTable table = new DataTable(); 时出现错误,提示 DataTable不包含一个接受0个参数的构造函数

But when I create DataTable table = new DataTable(); I get an error that DataTable does not contain a constructor that takes 0 arguments.

我发现了这个基本上说 DataTable 是.NET Core不再支持。那么现在怎么办?如何创建数据表(或其替代品)?如何将用户定义的表类型发送到.NET Core上的SQL Server?

I found this https://github.com/VahidN/EPPlus.Core/issues/4 which basically saying DataTable is no longer supported in .NET Core. So now what? how do I create a DataTable (or what is it's replacement)? how do I send a User-Defined Table Type to SQL Server on .NET Core?

推荐答案

.NET现在支持DataTable核心2.0。在。下面的示例代码在2.0中可用。

DataTable is now supported in .NET CORE 2.0. See my answer at .Net Core how to implement SQLAdapter ./ DataTable function . Sample code below works in 2.0.

public static DataTable ExecuteDataTableSqlDA(SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
{
   System.Data.DataTable dt = new DataTable();
   System.Data.SqlClient.SqlDataAdapter da = new SqlDataAdapter(cmdText, conn);
   da.Fill(dt);
   return dt;
}

这篇关于在.NET Core中使用DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:19
查看更多