在c#中的位置2没有行 [英] There is no row at the position 2. in c#

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

问题描述

嗨专家......我正在使用dataadapter和数据集从datagridview打印数据......但我得到的错误就像位置2没有行... plz帮我解决了这个问题...谢谢



我在以下代码中出现错误:



((DataTable) wddgv.DataSource).Rows [i + row];







Hi experts...I am printing data from datagridview using dataadapter and dataset...but i m getting error like There is no row at position 2...plz help me how i have to handle this...thanks

I m getting error in this statement in the following code:

((DataTable)wddgv.DataSource).Rows[i + row];



private void DrawGridBody(Graphics g, int y_value)
        {
            int x_value;

            for (int i = 0; i < 5; ++i)
            {
                DataRow dr =
                         ((DataTable)wddgv.DataSource).Rows[i + row];
                x_value = 0;

                // draw a solid line
                g.DrawLine(Pens.Black, new Point(0, y_value),
                        new Point(this.Width, y_value));

                foreach (DataGridViewColumn dc in wddgv.Columns)
                {
                    string text = dr[dc.DataPropertyName].ToString();

                    g.DrawString(text, this.Font, Brushes.Black,
                                             (float)x_value, (float)y_value + 10f);

                    x_value += dc.Width + 5;
                }

                y_value += 40;
            }

            row += 5;
        }

推荐答案

最好的办法是将for block限制为数据表中的行数。



for(.int i = 0; i< = wddgv.rows.count() - 1; i ++)

{

//这里的代码

}
Your best bet would be to restrict the for block to the number of rows in the data table.

for(.int i = 0; i <= wddgv.rows.count() - 1;i++)
{
//your code here
}


在检查条件之前

数据行数r else

u得到同样的错误

i认为数据库没有任何值,所以只能输入这个错误





DataRow dr =

((DataTable)wddgv.DataSource).Rows [i + row];
before that check condition
data row count r else
u getting same error
i think database not available any values so only comng this error


DataRow dr =
((DataTable)wddgv.DataSource).Rows[i + row];


这篇关于在c#中的位置2没有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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