You can just check below the
foreach
-loop if the
copyTable
contains any left-over rows.
Also, it appears you're doing some unneccessary stuff in the first
if
-block: You're double-initializing
copyTable
and you never use the DataSet
ds1
for anything. And I'm wondering what the
myDataList
is good for because you're sending it empty into
SendForProcessing(..)
and even if that method inserts something into it, after that you don't use it here. So it seems redundant to me, at least here - if you need one in
SendForProcessing(..)
then you could create it there. (
Unless you've left out code here.)
I've commented out the lines which I think aren't required or which I have replaced:
copyTable = ds.Tables[0].Clone();
foreach (DataRow dRow in ds.Tables[0].Rows)
{
copyTable.ImportRow(dRow);
if (copyTable.Rows.Count == 100)
{
new Program().SendForProcessing(copyTable);
copyTable = ds.Tables[0].Clone();
}
}
if (copyTable.Rows.Count > 0)
{
new Program().SendForProcessing(copyTable);
}