Reputation: 71
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.
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?
Library that I use: https://github.com/XML-Travelgate/xtg-data-sqlclient
Upvotes: 2
Views: 7581
Reputation: 6964
DataTable, DataSet etc can now be implemented using .NET Core 2.0 and Visual Studio 2017 Preview 15.3 +
Upvotes: 0
Reputation: 71
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
}
});
Upvotes: 5