急!急!异常详细信息: System.IndexOutOfRangeException: 在位置 9 处没有任何行。

fille19 2009-05-13 08:16:20
For k = 0 To ds2.Tables(0).Rows.Count - 1
tagnam = Trim(ds2.Tables(0).Rows(k)("tagnam")) '循环表里的n个位号

sqlstr10 = "select * from AVER_VALUE where TAGNAM = '" & tagnam & "' and (DRDATE between to_date('" & Trim(Tx_SDate.Text) & "','yyyy-mm-dd') and to_date('" & Trim(Tx_EDate.Text) & "','yyyy-mm-dd')) and PLANT='" & j & "' " 'or PART='" & j & "'
ds5 = GetDataFromOracle(sqlstr10) '取k位号里的其他值
plant = ds5.Tables(0).Rows(k)("PLANT")
descr = ds5.Tables(0).Rows(k)("DESCRIBE")
part = ds5.Tables(0).Rows(k)("PART")

sqlstr8 = "select distinct CLASSNAME from AVER_VALUE where TAGNAM = '" & tagnam & "' and (DRDATE between to_date('" & Trim(Tx_SDate.Text) & "','yyyy-mm-dd') and to_date('" & Trim(Tx_EDate.Text) & "','yyyy-mm-dd')) and PLANT='" & j & "' " 'or PART='" & j & "'
ds4 = GetDataFromOracle(sqlstr8) '平均值表里不同的班组
p = ds4.Tables(0).Rows.Count
For h = 0 To ds4.Tables(0).Rows.Count - 1
classname = Trim(ds4.Tables(0).Rows(h)("CLASSNAME")) '循环表里的n个班组
sqlstr6 = "select sum(AVER_VALUE) from AVER_VALUE where TAGNAM = '" & tagnam & "' and CLASSNAME = '" & classname & "' and (DRDATE between to_date('" & Trim(Tx_SDate.Text) & "','yyyy-mm-dd') and to_date('" & Trim(Tx_EDate.Text) & "','yyyy-mm-dd')) and PLANT='" & j & "' "
Dim cm2 As New OracleCommand(sqlstr6, conn)
sum = cm2.ExecuteScalar

sqlstr7 = "select * from AVER_VALUE where TAGNAM = '" & tagnam & "' and CLASSNAME = '" & classname & "' and (DRDATE between to_date('" & Trim(Tx_SDate.Text) & "','yyyy-mm-dd') and to_date('" & Trim(Tx_EDate.Text) & "','yyyy-mm-dd')) and PLANT='" & j & "' "
ds3 = GetDataFromOracle(sqlstr7) '某一位号一段时间内的n个值
count2 = ds3.Tables(0).Rows.Count
aver = sum / count2

addstr = "insert into AVER_VALUE_LS values ('" & plant & "','" & descr & "','" & tagnam & "'," & aver & ",'" & part & "','" & classname & "',to_date('" & Trim(Tx_SDate.Text) & "','yyyy-mm-dd'),to_date('" & Trim(Tx_EDate.Text) & "','yyyy-mm-dd'))"
Oraclecommand(addstr)
Next
Next





在此位置处 plant = ds5.Tables(0).Rows(k)("PLANT")报异常详细信息: System.IndexOutOfRangeException: 在位置 9 处没有任何行。

但是我的数据库里确实有值,不是每个时间段都报错,有的报、有的不报。

各位有没有碰到过这种情况的,请回贴啊。。。。。。。。。。。。。。。
...全文
396 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tensionli 2009-05-13
  • 打赏
  • 举报
回复
索引溢出的异常,你给的索引超出了它的上限,好好看一下代码吧
starj1 2009-05-13
  • 打赏
  • 举报
回复
For k = 0 To ds2.Tables(0).Rows.Count - 1
tagnam = Trim(ds2.Tables(0).Rows(k)("tagnam")) '循环表里的n个位号

sqlstr10 = "select * from AVER_VALUE where TAGNAM = '" & tagnam & "' and (DRDATE between to_date('" & Trim(Tx_SDate.Text) & "','yyyy-mm-dd') and to_date('" & Trim(Tx_EDate.Text) & "','yyyy-mm-dd')) and PLANT='" & j & "' " 'or PART='" & j & "'
ds5 = GetDataFromOracle(sqlstr10) '取k位号里的其他值
plant = ds5.Tables(0).Rows(k)("PLANT")

你用的控制变量k是ds2里的表0的数据行数,能代表ds5一定有ds2的表0的数据行数?
jest850615 2009-05-13
  • 打赏
  • 举报
回复
看字面意思应该是你的 k 超标了
madong871020 2009-05-13
  • 打赏
  • 举报
回复
你可以try catch 捕获异常啊,或者强制转换string 有null时也可以取个“”啊
zgke 2009-05-13
  • 打赏
  • 举报
回复
哪个下标溢出了把.
麻子Mozart 2009-05-13
  • 打赏
  • 举报
回复
顶一下
madong871020 2009-05-13
  • 打赏
  • 举报
回复
应该是有的“plant”插入了null所以报错
madong871020 2009-05-13
  • 打赏
  • 举报
回复
先说你的代码写的很乱......这么多sql语句,咋不用存储过程啊,代码也很不规范啊
fille19 2009-05-13
  • 打赏
  • 举报
回复
感谢各位热心的解答!

特别是“木古口十”就是那个问题,两个数据集ds2和ds5的值,虽然是相同条件sql语句的,但我并不能确定它们一致。我把这个改了就好了。

“冬风瘦马”说的也很对,我的sql是乱了点。存储过程怎么用?我理解存储过程是在数据库中建设的,我对oracle不怎么熟悉。请指教。

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧