ADO.NET No Row At Position X Error

W

wackyphill

I keep getting this error on a scheduling program I'm working on and
don't know why. It seems to be the last row in the view always that
gets the error.

The Code W/ The Error: (_db is a wrapper around some ADO Objects)


int freq;
int days;
DateTime now = DateTime.Now;
string where = string.Format("runTime <= '{0}'", now);
bool bEnabled = false;
string path = null;
DataView runView = new DataView( _db.DS.Tables["task"], where, null,
DataViewRowState.CurrentRows);

foreach( DataRowView row in runView )
{
//Pull Values
freq = (int)row["freq"];
dt = (DateTime)row["runTime"];
days = (int)row["days"];
bEnabled = (bool)row["enabled"];
path = (string)row["path"];

//Update Time For Task To Run Next
if( freq == 0 ) { dt = dt.AddDays(1); }
else { dt = dt.AddMinutes(freq); }
row.BeginEdit();
row["runTime"] = dt;
row.EndEdit();

//Test If Task Should Run Today
int todayMask = (int)Math.Pow(2, (double)now.DayOfWeek);
if( (todayMask & days) == 0 ) { continue; }

//Run, If Enabled
if( bEnabled ) { RunProcess( path ); }
}
_db.Task_ApplyChanges();
RefreshTasks();
 
W

wackyphill

I am not sure, but I believe it occurs when the record is modified.

row["runTime"] = dt;
 
W

wackyphill

This is the error. But I get no line #:


There is no row at position 3.
at System.Data.DataView.GetRecord(Int32 recordIndex)
at System.Data.DataView.IsOriginalVersion(Int32 index)
at System.Data.DataRowView.get_Item(String property)
at ScheduleManager.MainFrm.timer_Tick(Object sender, EventArgs e)
 
W

wackyphill

OK Tried it in .NET 2.0b add it does show the line #.

Is happens when the row is accessed first.
---> freq = (int)row["freq"];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top