与其批量处理这么多的记录数,不如采用更简单的方法。您希望在某个日期 (2010-01-01) 之前杀死所有内容。
为什么不尝试从 2009 年 12 月 31 日开始,并继续回溯到您要清除的文件的最早日期。另请注意,我不知道 Departure 是日期还是日期时间,所以我将其更改为
TTOD(Departure)(意味着将时间转换为日期部分)
DateTime purgeDate = new DateTime(2009, 12, 31);
// the "?" is a parameter place-holder in the query
string SQLtxt = "delete from TableA "
+ " where TableA.Key in ( "
+ " select Key from TableB "
+ " where TTOD( Departure ) < ? and Key <> \"\" )";
OleDbCommand oSQL = new OleDbCommand( SQLtxt, YourOleDbConnectionHandle );
// default the "?" parameter place-holder
oSQL.Parameters.AddWithValue( "parmDate", purgeDate );
int RecordsDeleted = 0;
while( purgeDate > new DateTime(2000,1,1) )
{
// always re-apply the updated purge date for deletion
oSQL.Parameters[0].Value = purgeDate;
RecordsDeleted += oSQL.ExecuteNonQuery();
// keep going back one day at a time...
purgeDate = purgeDate.AddDays(-1);
}
这样,无论您处理什么 RECNO() 都无关紧要,它只会执行特定日期的任何键。如果您一天有超过 10,000 个条目,那么我可能会采用不同的方法,但由于这更像是一次清理,我不会太在意进行 1000 多次迭代(无论多少年,每年 365 天) )通过数据...或者,您可以使用日期范围进行操作,并且可能每周进行一次,只需更改 WHERE 子句并调整参数...类似于...(2000 年 1 月 1 日的日期只是猜测数据可以追溯到多远)。此外,由于这是整个日期范围,因此无需转换出发字段的可能 TTOD()。
DateTime purgeDate = new DateTime(2009, 12, 31);
DateTime lessThanDate = new DateTime( 2010, 1, 1 );
// the "?" is a parameter place-holder in the query
string SQLtxt = "delete from TableA "
+ " where TableA.Key in ( "
+ " select Key from TableB "
+ " where Departure >= ? "
+ " and Departure < ? "
+ " and Key <> \"\" )";
OleDbCommand oSQL = new OleDbCommand( SQLtxt, YourOleDbConnectionHandle );
// default the "?" parameter place-holder
oSQL.Parameters.AddWithValue( "parmDate", purgeDate );
oSQL.Parameters.AddWithValue( "parmLessThanDate", LessThanDate );
int RecordsDeleted = 0;
while( purgeDate > new DateTime(2000,1,1) )
{
// always re-apply the updated purge date for deletion
oSQL.Parameters[0].Value = purgeDate;
oSQL.Parameters[1].Value = lessThanDate;
RecordsDeleted += oSQL.ExecuteNonQuery();
// keep going back one WEEK at a time for both the starting and less than end date of each pass
purgeDate = purgeDate.AddDays(-7);
lessThanDate = lessThanDate.AddDays( -7);
}