My program is making a query from one database and I want that query to be added to a stored procedure in another database. At first I was insert each parameter as a List, but I want to optimize the code and insert all parameters into one List. I add all select options to list:
public void GetResult(SqlCommand command)
{
var list = new List<Models>;
using(var reader = command.ExecuteReader())
while (reader.Read())
{
var rows = new Models;
rows.Md1 = Convert.ToInt32(reader["md1"]);
rows.Md2 = Convert.ToInt32(reader["md2"]);
list.Add(rows);
}
using var InsertCommand = new OracleCommand();
InsertCommand.CommandText = "PathToProcedure";
var Param1 = new OracleParameter("param1", OracleDbType.Int32, ParameterDirecion.Input);
Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
Param1.Value =
Param2.Size =
}
Question: How to create a link to these rows to insert them in parameters? Thanks in advance!
SP:
create or replace package body transfer_package is
procedure getdt(param1 in t_number,
param2 in t_number)
is
begin
if param1.count > 0 then
for i in 1 .. param1.count loop
insert into table
(parameter1,
parameter2)
values
(param1(i),
param2(i));
end loop;
end;
CodePudding user response:
The solution of my question is a Linq library...
Param1.Value = list.Select(Models => Models.Md1).ToArray();
Param2.Size = list.Select(Models => Models.Md2).ToArray();
and so on