我有一个返回新 ID 的存储过程。
create proc [dbo].[WriteIT]
(@deg nvarchar(max))
as
DECLARE @s nvarchar(max)
set @s = 'INSERT INTO test OUTPUT inserted.ID VALUES '
set @s += @deg
exec (@s)
如何将存储过程的多个结果放入一个int[]
?
string con = "Server=.;Database=Adb;Trusted_Connection=True";
SqlConnection connet = new SqlConnection(con);
SqlCommand cm = new SqlCommand("WriteIT", connet);
cm.CommandType = System.Data.CommandType.StoredProcedure;
bd = new StringBuilder();
string veri = "({0}),";
string sablon = "'{0}','{1}'";
for (int i = 0; i < 50; i++)
{
bd.Append(string.Format(veri, string.Format(sablon, new Random().Next(0, 100000).ToString(), new Random().Next(0, 100000).ToString())));
}
cm.Parameters.AddWithValue("@deger", bd.ToString().Substring(0, bd.Length - 1));
if (connet.State == System.Data.ConnectionState.Closed)
connet.Open();
string a = cm.ExecuteScalar();