我使用C Sharp
运行调试器后出现此错误,以查看代码有什么问题:
{"位置5没有行。"} System.Exception {System.IndexOutOfRangeException}
dt = new DataTable();
dt = objReport.USERWISEACCOUNTINGINFORMATIONWITHINBOUNDOUTBOUND(strDomainName, 0, fromDate, toDate);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
DataTable dt1 = dt.AsEnumerable().Take(4).CopyToDataTable();
int[] YPointMember = new int[dt1.Rows.Count];
DateTime[] XPointMember = new DateTime[dt1.Rows.Count];
for (int count = 0; count < dt1.Rows.Count; count++)
{
YPointMember[count] = Convert.ToInt32(dt1.Rows[count]["INBOUND"]);
XPointMember[count] = Convert.ToDateTime(dt1.Rows[count]["connectdatetime"]);
}
Chart1.Series[0].Points.DataBindXY(YPointMember, XPointMember);
Chart1.Series[0].BorderWidth = 1;
Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:HH";
Chart1.ChartAreas[0].AxisY.LabelStyle.Format = "h : h";
Chart1.ChartAreas[0].AxisY.Interval = 2;
Chart1.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Hours;
Chart1.ChartAreas[0].AxisY.IntervalOffset = 0;
}
}
答案 0 :(得分:0)
问题出在这里。
DataTable dt1 = dt.AsEnumerable().Take(4).CopyToDataTable();
Take(4)
正试图从表中获取4行。如果表中没有四行,则会产生相同的错误。