Without knowing what your table structure is and what the data is that you are passing... it is really hard to help you.
Not only that; while the code is within C# the actual problem you are experiencing is within SQL. And again you not specified what kind of SQL you are actually using
So I am going to answer this based on:
1. OriginalGriff is correct with the Error_Codes being an array.
2. You are using a version of (MS) SQL Server released within the last 5 years.
If this was my task; I would
_ Create a
Stored Procedure on the SQL Server to do this
_ Pass the array value to the Stored Procedure as a comma-delineated string
Stored Procedure would utilize the
String_Split
function, and returns a table with one row per delineated value.
CREATE PROCEDURE dbo.Table2_Insert (
@Diagnostic_Data NVARCHAR(100),
@Error_Codes NVARCHAR(100),
@Input_Output NVARCHAR(100),
@Shift_Inhibits NVARCHAR(100)
) AS
BEGIN
INSERT into Table_2
SELECT @Diagnostic_Data
, value
, @Input_Output
, @Shift_Inhibits
FROM String_Split('@Error_Codes', ',');
END
GO
Within your C# code, there would be minimal alterations
_ Change the SQL Command Text
_ Set the SQL Command
CommandType
_ Convert the
Error_Codes
array to a delineated-string
cmd = new SqlCommand("Table2_Insert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@Diagnostic_Data", display_diagnostic_data);
cmd.Parameters.AddWithValue("@Error_Codes", String.Join(",", Error_Codes));
cmd.Parameters.AddWithValue("@Input_Output", Input_Output);
cmd.Parameters.AddWithValue("@Shift_Inhibits", Shift_Inhibits);
conn.Open();
int RowsAffected = cmd.ExecuteNonQuery();
conn.Close();
References:
MS Docs: SQL Split_String()[
^]
MS DOCS: C# String.Join()[
^]