错误 - 位置35处没有行。 [英] Error- there is no row at position 35.

查看:66
本文介绍了错误 - 位置35处没有行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

error- There is no row at position 35.





我尝试过:





What I have tried:

try
      {
          DataTable dt = new DataTable();
          //string str = "select round(Avg(Score),2) as Score from oeunitscore";
          string str = @"select om.unitgroup, round(Avg(Score),2) as Score, date(timestamp) as TimeStamp  from oeunitscore os, oeunitmaster om
                              where os.unitcode=om.unitcode and date(timestamp) BETWEEN SYSDATE() - interval 11 day AND SYSDATE()
                              group by  unitgroup, date(timestamp)
                              order by date(timestamp) , unitgroup asc";
          if (con.State == ConnectionState.Closed)
          {
              con.Open();
          }
          MySqlDataAdapter da = new MySqlDataAdapter(str, con);
          da.Fill(dt);
          if (dt.Rows.Count > 0)
          {
              date1 = Convert.ToDateTime(dt.Rows[0]["TimeStamp"]).ToString("dd-MM-yy");
              date2 = Convert.ToDateTime(dt.Rows[7]["TimeStamp"]).ToString("dd-MM-yy");
              date3 = Convert.ToDateTime(dt.Rows[14]["TimeStamp"]).ToString("dd-MM-yy");
              date4 = Convert.ToDateTime(dt.Rows[21]["TimeStamp"]).ToString("dd-MM-yy");
              date5 = Convert.ToDateTime(dt.Rows[28]["TimeStamp"]).ToString("dd-MM-yy");
              date6 = Convert.ToDateTime(dt.Rows[35]["TimeStamp"]).ToString("dd-MM-yy");
              date7 = Convert.ToDateTime(dt.Rows[42]["TimeStamp"]).ToString("dd-MM-yy");

              dh1 = Convert.ToSingle(dt.Rows[0]["Score"].ToString());
              di1 = Convert.ToSingle(dt.Rows[1]["Score"].ToString());
              fr1 = Convert.ToSingle(dt.Rows[2]["Score"].ToString());
              gf1 = Convert.ToSingle(dt.Rows[3]["Score"].ToString());
              lr1 = Convert.ToSingle(dt.Rows[4]["Score"].ToString());
              of1 = Convert.ToSingle(dt.Rows[5]["Score"].ToString());
              ut1 = Convert.ToSingle(dt.Rows[6]["Score"].ToString());

              dh2 = Convert.ToSingle(dt.Rows[7]["Score"].ToString());
              di2 = Convert.ToSingle(dt.Rows[8]["Score"].ToString());
              fr2 = Convert.ToSingle(dt.Rows[9]["Score"].ToString());
              gf2 = Convert.ToSingle(dt.Rows[10]["Score"].ToString());
              lr2 = Convert.ToSingle(dt.Rows[11]["Score"].ToString());
              of2 = Convert.ToSingle(dt.Rows[12]["Score"].ToString());
              ut2 = Convert.ToSingle(dt.Rows[13]["Score"].ToString());

              dh3 = Convert.ToSingle(dt.Rows[14]["Score"].ToString());
              di3 = Convert.ToSingle(dt.Rows[15]["Score"].ToString());
              fr3 = Convert.ToSingle(dt.Rows[16]["Score"].ToString());
              gf3 = Convert.ToSingle(dt.Rows[17]["Score"].ToString());
              lr3 = Convert.ToSingle(dt.Rows[18]["Score"].ToString());
              of3 = Convert.ToSingle(dt.Rows[19]["Score"].ToString());
              ut3 = Convert.ToSingle(dt.Rows[20]["Score"].ToString());

              dh4 = Convert.ToSingle(dt.Rows[21]["Score"].ToString());
              di4 = Convert.ToSingle(dt.Rows[22]["Score"].ToString());
              fr4 = Convert.ToSingle(dt.Rows[23]["Score"].ToString());
              gf4 = Convert.ToSingle(dt.Rows[24]["Score"].ToString());
              lr4 = Convert.ToSingle(dt.Rows[25]["Score"].ToString());
              of4 = Convert.ToSingle(dt.Rows[26]["Score"].ToString());
              ut4 = Convert.ToSingle(dt.Rows[27]["Score"].ToString());

              dh5 = Convert.ToSingle(dt.Rows[28]["Score"].ToString());
              di5 = Convert.ToSingle(dt.Rows[29]["Score"].ToString());
              fr5 = Convert.ToSingle(dt.Rows[30]["Score"].ToString());
              gf5 = Convert.ToSingle(dt.Rows[31]["Score"].ToString());
              lr5 = Convert.ToSingle(dt.Rows[32]["Score"].ToString());
              of5 = Convert.ToSingle(dt.Rows[33]["Score"].ToString());
              ut5 = Convert.ToSingle(dt.Rows[34]["Score"].ToString());

              dh6 = Convert.ToSingle(dt.Rows[35]["Score"].ToString());
              di6 = Convert.ToSingle(dt.Rows[36]["Score"].ToString());
              fr6 = Convert.ToSingle(dt.Rows[37]["Score"].ToString());
              gf6 = Convert.ToSingle(dt.Rows[38]["Score"].ToString());
              lr6 = Convert.ToSingle(dt.Rows[39]["Score"].ToString());
              of6 = Convert.ToSingle(dt.Rows[40]["Score"].ToString());

推荐答案

错误信息不能更清楚:

The error message could not be more clear:
There is no row at position 35.

您的代码使用显式行号;

Your code uses explicit row numbers;

date1 = Convert.ToDateTime(dt.Rows[0]["TimeStamp"]).ToString("dd-MM-yy");
date2 = Convert.ToDateTime(dt.Rows[7]["TimeStamp"]).ToString("dd-MM-yy");
date3 = Convert.ToDateTime(dt.Rows[14]["TimeStamp"]).ToString("dd-MM-yy");
date4 = Convert.ToDateTime(dt.Rows[21]["TimeStamp"]).ToString("dd-MM-yy");
date5 = Convert.ToDateTime(dt.Rows[28]["TimeStamp"]).ToString("dd-MM-yy");
date6 = Convert.ToDateTime(dt.Rows[35]["TimeStamp"]).ToString("dd-MM-yy");
date7 = Convert.ToDateTime(dt.Rows[42]["TimeStamp"]).ToString("dd-MM-yy");

没有以任何方式检查是否有足够的结果返回以容纳它们:您需要返回至少43行才能使其正常工作。



你为什么不拿到它们?我们无法分辨,因为我们无法访问您的数据或结果。

首先使用调试器检查您从查询中获得的实际结果,并找出有多少是,然后检查你的数据,看看你有多少期待。

然后添加代码来检查你是否有预期的返回行数,如果没有则报告问题。



并帮自己一个忙:停止使用魔术数字来选择你的行:为什么你想要七行中的行,这一点并不明显,但可能它是某种日常数据你想要的星期日或类似的。但是使用反映使用情况的东西(可能是一个常数?),而不是7,14,21,28,......告诉任何人什么!

without checking in any way that there are sufficient results returned to accommodate them: you need at least 43 rows returned in order for that to work.

Why don't you get them? We can't tell, because we have no access to your data or to your results.
Start by using the debugger to examine the actual results you get back from your query, and find out how many there are, and then check your data to see how many you were expecting.
Then add code to check you have the expected number of rows returned, and report a problem if not.

And do yourself a favour: stop using "magic numbers" to select your rows: it's not at all obvious why you want rows in sevens, but probably it's some kind of daily data and you want Sunday only or similar. But use something (a constant perhaps?) that reflects the usage, not 7, 14, 21, 28 , ... that tells nobody anything!


这篇关于错误 - 位置35处没有行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆