获取数据表中行的值c#
我的代码有问题。
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;
}
但我需要 xATmax 和 yATmax 下一行的值...有人可以帮助我吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那么不要使用 foreach 。 使用“for 循环”。 您的代码有点混乱,但您可以执行类似的操作...
请注意,您必须考虑到最后一行不会有“i+1”,因此您必须使用 if 语句来捕获它。
Dont use a foreach then. Use a 'for loop'. Your code is a bit messed up but you could do something like...
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.
在循环中,您现在可以引用第 i+1 行(假设有一个 i+1)
In the loop, you can now reference row i+1 (assuming there is an i+1)
for (Int32 i = 1; i < dt_pattern.Rows.Count - 1; i++){
双 yATmax = ToDouble(dt_pattern.Rows[i]["Ampl"].ToString()) + AT;
}
如果你想解决+1问题
for (Int32 i = 1; i < dt_pattern.Rows.Count - 1; i++){
double yATmax = ToDouble(dt_pattern.Rows[i]["Ampl"].ToString()) + AT;
}
if you want to get around the + 1 issue