首页 > 解决方案 > datagridview c#的参数超出范围异常

问题描述

在 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);



            ...

标签: c#databasearguments

解决方案


推荐阅读