在.NET Core中使用DataTable

编程入门 行业动态 更新时间:2024-10-28 11:26:16
本文介绍了在.NET Core中使用DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在SQL Server中有一个存储过程,该存储过程接受用户定义的表类型。我正在关注这篇帖子的答案从C#列表批量插入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.

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

I found this github/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。在 .Net Core如何实现SQLAdapter ./ DataTable中查看我的答案功能。下面的示例代码在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

本文发布于:2023-11-04 11:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557793.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   Core   DataTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!