D
D
Dmitry Gavrilenko2017-04-13 14:15:30
.NET
Dmitry Gavrilenko, 2017-04-13 14:15:30

How to pass multiple rows of data to a stored procedure?

Hello.
There are 2 HP. One returns data, the second data must be transferred.
Both work with collections of data.
With HP which returns the data understood. Because I work with .NET Core, and it does not have a DataTable, I had to create my own wrapper class for the returned data. Essentially I have a multidimensional data array. With this, everything is clear.
A question on , which should accept these data.
SqlParameter allows you to create a parameter and pass data to it. It's not a problem. I don't know how to pass an array of data.
Tell me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2017-04-13
@Maddox

In .NET Core, DataTable is replaced with List<SqlDataRecord>
Example:

private SqlParameter CreateTableGuidParameter(string name, Guid[] ids)
{
      var tableParam = new SqlParameter(name, SqlDbType.Structured);
      tableParam.TypeName = "[dbo].[TableUniqueIdentifierType]";
      tableParam.Direction = ParameterDirection.Input;

      var rows = new List<SqlDataRecord>();
      var sqlMetaData = new SqlMetaData("Id", SqlDbType.UniqueIdentifier);
      foreach (var id in ids)
      {
           var row = new SqlDataRecord(sqlMetaData);
           row.SetValues(id);
           rows.Add(row);
     }
     tableParam.Value = rows;
     return tableParam;
}

D
d-stream, 2017-04-13
@d-stream

In my opinion, "regularly" this is in the form of xml or json (the first seems to be from 2008, the second - later)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question