datagridview c#的参数超出范围异常

时间:2020-01-16 18:43:49

标签: c# database arguments

在DataGridView上显示数据期间出现错误 我认为这与-1问题有关,但是我该如何处理我无法达到的这3个条件。 当数据计数为3时没问题。

当数据计数为2或1时,程序会出现错误,例如参数超出范围异常。

            ...
        DataTable abc = new DataTable();
        sda.Fill(abc);

        DataGridView.DataSource = abc;


        if (Convert.ToString(DataGridView.Rows[0].Cells["xyz"].Value) != null  && Convert.ToString(DataGridView.Rows[1].Cells["xyz"].Value) != null  && Convert.ToString(DataGridView.Rows[2].Cells["xyz"].Value) != null)
        {
            textbox1.Text = Convert.ToString(DataGridView.Rows[0].Cells["xyz"].Value);
            textbox2.Text = Convert.ToString(DataGridView.Rows[1].Cells["xyz"].Value);
            textbox3.Text = Convert.ToString(DataGridView.Rows[2].Cells["xyz"].Value);



            ...

0 个答案:

没有答案