Datatable class in asp.net core

If you tried to use SQLClient in the asp.net kernel, you may have noticed the absence of DataTables and DataSets, the table structures used for database I / O.

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

The library I'm using: https://github.com/XML-Travelgate/xtg-data-sqlclient

+2
source share
2 answers

Decision:

        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
                }
            });
+5

DataTable, DataSet .. .NET Core 2.0 Visual Studio 2017 Preview 15.3 +

0

Source: https://habr.com/ru/post/1674561/


All Articles