If you have SQL-Server Express edition you can perform a bulk insert, use a SQL SELECT WHERE to get at the data you want them empty the table.
Using a connection and command object example for the SQL
BEGIN TRANSACTION
BEGIN TRY
BULK INSERT dbo.BulkDataTable
FROM 'C:\SomePath\SomeFile.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
ROWS_PER_BATCH = 10000,
TABLOCK
)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
Sample export code
public static void ToCommaDelimited()
{
var selectStatement = "TODO";
using var cn = new SqlConnection("TODO");
using var cmd = new SqlCommand { Connection = cn, CommandText = selectStatement };
cn.Open();
var reader = cmd.ExecuteReader();
var fileName = "C:\\SomePath\\test.csv";
var streamWriter = new StreamWriter(fileName);
var output = new object[reader.FieldCount];
for (int index = 0; index < reader.FieldCount; index++)
{
output[index] = reader.GetName(index);
}
streamWriter.WriteLine(string.Join(",", output));
while (reader.Read())
{
reader.GetValues(output);
streamWriter.WriteLine(string.Join(",", output));
}
}