To create a local temporary table, just execute a DDL command:
SqlConnection conn = new SqlConnection(sqlConnectionString);
string sql = @"IF OBJECT_ID('tempdb..#List') IS NOT NULL TRUNCATE TABLE #List ELSE
CREATE TABLE #List(Channel_Key int PRIMARY KEY)"
SqlCommand cmdDDL = new SqlCommand(sql, conn);
cmdDDL.ExecuteNonQuery();
Then populate the table. I typically create a simple stored procedure to do the population:
CREATE PROC dbo.FillList @Channel_Key int AS
SET NOCOUNT ON;
INSERT #List(Channel_Key)
VALUES(@Channel_Key);
In C#, execute that in your loop to insert a row for each value, and then execute the SP to delete the channels:
SqlCommand cmdFillList = new SqlCommand("dbo.FillList", conn);
cmdFillList.CommandType = CommandType.StoredProcedure;
cmdFillList.Parameters.Add("@Channel_Key", SqlDbType.Int);
foreach (int channelKey in channelDeletes)
{
cmdFillList.Parameters["@Channel_Key"].Value = channelKey;
cmdFillList.ExecuteNonQuery();
}
SqlCommand cmdDeleteChannels = new SqlCommand("dbo.DeleteChannels", conn);
cmdDeleteChannels.CommandType = CommandType.StoredProcedure;
cmdDeleteChannels.ExecuteNonQuery();
Note that the stored procedure that does the work takes no parameters. Because all your SQL commands share the same connection, the local temporary table is visible (in scope) to them but not to other connections.
From your narrative, I don't believe you need to change the Channel_Order values after the delete. As I implied in my earlier reply, one shouldn't do unnecessary updates in SQL, particularly if they could affect many rows. Your display order will be unchanged if you leave the gaps in the Channel_Order column. So my recommendation is to use just a stored procedure like this:
CREATE PROC dbo.DeleteChannels AS
SET NOCOUNT ON;
DELETE c
FROM dbo.Channel c JOIN #List t ON c.Channel_Key = t.Channel_Key;
If you have a legitimate reason for removing the gaps (and, again, you haven't provided one), then just use what I already suggested but exclude the rows with zero Channel_Order:
CREATE PROC dbo.DeleteChannels AS
SET NOCOUNT ON;
BEGIN TRAN;
DELETE c
FROM dbo.Channel c JOIN #Values t ON c.Channel_Key = t.Channel_Key;
WITH cte AS
(SELECT Channel_Key, ROW_NUMBER() OVER (ORDER BY Channel_Order) AS NewOrder
FROM dbo.Channel
WHERE Channel_Order > 0)
UPDATE cte SET Channel_Order = NewOrder
WHERE Channel_Order > NewOrder;
COMMIT TRAN;