ASP.NET Core中的数据表类

编程入门 行业动态 更新时间:2024-10-19 00:22:25
本文介绍了ASP.NET Core中的数据表类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果您试图在asp核心中使用SQLClient,您可能会注意到缺少用于数据库I / O的表结构DataTables和DataSets。

If you have tried to use SQLClient in asp core, you might have noticed the absence of the DataTables and DataSets, tables structures used to I/O of database.

对于输出数据,我们可以选择SqlDataReader。 但是对于输入数据,我还没有找到解决此问题的方法-例如如果您想通过框架461中的参数将表传递给SP,则使用 SqlDbType = SqlDbType.Structured and DataTable类。 任何想法有人吗?

For output data we have the option of SqlDataReader. But for the input data, I'm yet to find a solution to this problem -e.g. if you want pass a table to SP by parameter in framework 461, we use 'SqlDbType = SqlDbType.Structured and DataTable class'. Any ideas anyone?

我使用的库: github/XML-Travelgate/xtg-data-sqlclient

推荐答案

解决方案:

List<SqlDataRecord> datatable = new List<SqlDataRecord>(); SqlMetaData[] sqlMetaData = new SqlMetaData[2]; sqlMetaData[0] = new SqlMetaData("id", SqlDbType.Int); sqlMetaData[1] = new SqlMetaData("name", SqlDbType.VarChar, 50); SqlDataRecord row = new SqlDataRecord(sqlMetaData); row.SetValues(new object[] { 1, "John" }); datatable.Add(row); row = new SqlDataRecord(sqlMetaData); row.SetValues(new object[] { 2, "Peter" }); datatable.Add(row); var task = dbBase.ExecProcedureDataTableWithParamsAsync<object>("VIEWTABLE", new List<SqlParameter>() { new SqlParameter() { ParameterName = "@paramtable", SqlDbType = SqlDbType.Structured, Direction = ParameterDirection.Input, Value = datatable } });

更多推荐

ASP.NET Core中的数据表类

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

发布评论

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

>www.elefans.com

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