As per my understanding, the job return the result to an application (C#), then this application is calling the DB for each record.
The Answer is yes, you can send multiple records (datatable) to the sql server in one patch then the sql server will process all these data.
First in SQL Server, you have to define a table datatype of the format which will be sent from the application to the DB.
CREATE TYPE YourDataType AS TABLE(
[Col1] [int] NULL, [Col2] [int] NULL, [Col3] [int] NULL, [Col4] [nvarchar](255) NULL,
[Col5] [nvarchar](255) NULL, [Col6] [nvarchar](255) NULL, [Col7] [nvarchar](255) NULL, [Col8] [nvarchar](255) NULL,
[Col9] [nvarchar](255) NULL, [Col10] [nvarchar](255) NULL, [Col11] [int] NULL, [Col12] [nvarchar](255) NULL,
)
GO
Then create your procedure which will use this datatype
CREATE PROCEDURE YourProcedureName (@TableVariable YourDataType READONLY, @ScalarParameter nvarchar(255))
AS
BEGIN
INSERT INTO YourTable WITH (ROWLOCK) (Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12 )
SELECT Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12
FROM @TableVariable t
/*Left Join then where ID is null to make sure the record doesn't exists*/
LEFT JOIN YourTable PR WITH (NOLOCK)
ON PR.ID = @ScalarParameter
AND PR.Col1 = t.Col1
AND PR.Col2 = t.Col2
......
WHERE PR.ID IS NULL
END
Finally call this procedure from your application using your data.
Here i wrote it using VB.Net but you can rewrite it in C#:
Dim connectionString As StringBuilder = New StringBuilder()
connectionString.AppendFormat("Server={0};", ????)
connectionString.AppendFormat("Database={0};", ???)
connectionString.AppendFormat("User ID={0};", ????)
connectionString.AppendFormat("Password={0}", ????)
Dim InputTable As DataTable = New DataTable("YourDataType")
InputTable = ds.Tables(0).Copy()
InputTable.TableName = "YourDataType"
Try
Using conn As New SqlClient.SqlConnection(connectionString.ToString())
Using comm As New SqlClient.SqlCommand()
Dim insertedRecords As Int32
comm.Connection = conn
comm.CommandText = "YourProcedureName"
comm.CommandType = CommandType.StoredProcedure
Dim TableVariable As SqlClient.SqlParameter = comm.Parameters.Add("@TableVariable", SqlDbType.Structured)
TableVariable.Direction = ParameterDirection.Input
TableVariable.Value = InputTable
Dim ScalarVariable As SqlClient.SqlParameter = comm.Parameters.Add(@ScalarParameter, SqlDbType.VarChar)
ScalarVariable.Direction = ParameterDirection.Input
ScalarVariable.Value = ???
conn.Open()
insertedRecords = comm.ExecuteNonQuery()
If (insertedRecords > 0) Then
_Changed = True
End If
conn.Close()
comm.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
Return False
End Try
Return True