本文介绍了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中的数据表类
发布评论