Get Value of Row in Datatable c#

subprime picture subprime · Jun 21, 2009 · Viewed 158k times · Source

i have a problem with my code.

foreach (DataRow dr in dt_pattern.Rows)
    {
      part = dr["patternString"].ToString();
      if (part != vpart)
      {
        System.Console.WriteLine(part);
        System.Console.WriteLine("Geben Sie bitte für den Abschnitt die AT ein: ");
        temp = System.Console.ReadLine();
        AT = ToDouble(temp);
        dr["AT"] = AT;

        double xATmax = ToDouble(dr["Ampl"].ToString());
        double x = ToDouble(dr["Time"].ToString());

        double yATmax = ToDouble(dr["Ampl"]+1.ToString()) + AT;
        double y = ToDouble(dr["Ampl"].ToString());

        dr["alphaATmin"] = Gradient(x,xATmax,y,yATmax);
        System.Console.WriteLine(dr["alphaATmin"]);
      }
      vpart = part;          
    }

but i need at xATmax and yATmax the Value of the next Row... Someone can help me ?

Answer

user110714 picture user110714 · Jun 21, 2009

Dont use a foreach then. Use a 'for loop'. Your code is a bit messed up but you could do something like...

for (Int32 i = 0; i < dt_pattern.Rows.Count; i++)
{
    double yATmax = ToDouble(dt_pattern.Rows[i+1]["Ampl"].ToString()) + AT;
}

Note you would have to take into account during the last row there will be no 'i+1' so you will have to use an if statement to catch that.