[英]Datatable class in asp.net core
If you have tried to use SQLClient in asp.net core, you might have noticed the absence of the DataTables and DataSets, tables structures used to I/O of database. 如果您试图在asp.net核心中使用SQLClient,则可能已经注意到缺少用于数据库I / O的表结构DataTables和DataSets。
For output data we have the option of SqlDataReader. 对于输出数据,我们可以选择SqlDataReader。 But for the input data, I'm yet to find a solution to this problem -eg if you want pass a table to SP by parameter in framework 461, we use 'SqlDbType = SqlDbType.Structured and DataTable class'. 但是对于输入数据,我还没有找到解决此问题的方法-例如,如果要通过框架461中的参数将表传递给SP,我们使用'SqlDbType = SqlDbType.Structured and DataTable class'。 Any ideas anyone? 有任何想法吗?
Library that I use: https://github.com/XML-Travelgate/xtg-data-sqlclient 我使用的库: https : //github.com/XML-Travelgate/xtg-data-sqlclient
Solution: 解:
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
}
});
现在可以使用.NET Core 2.0和Visual Studio 2017 Preview 15.3 +来实现DataTable,DataSet等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.