I have been getting a strange error during run time.
I looked into my code and I specifically make it sure that this doesn't happen by using Rows.Count
(for supportPointSelected
). I check the Count and if and only of its lager than 0 (the First IF
statement of the code) I go ahead with it. Please find the code below.
private List<byte> routeHandler(DataTable supportPointSelected, double taskState, int indices)
{
//TPCANStatus statusCan = new TPCANStatus();
int a = supportPointSelected.Columns.IndexOf("Number"); // column number indices
int b = supportPointSelected.Columns.IndexOf("XSupport"); // column number X
int c = supportPointSelected.Columns.IndexOf("YSupport"); // column number Y
int d = supportPointSelected.Columns.IndexOf("VSupport"); // column number Velocity
if (supportPointSelected.Rows.Count > 0) // Check to Avoid the Error
{
if (Convert.ToDouble(supportPointSelected.Rows[0][d]) == 0)
{
supportPointSelected.Rows[0][d] = 0.01; // This is the Point the Error Occurs
}
else { }
}
else { }
List<byte> output = new List<byte>();
// Logic do Something
return output;
}