Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# datagridview c的参数超出范围异常#_C#_Database_Arguments - Fatal编程技术网

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

C# datagridview c的参数超出范围异常#,c#,database,arguments,C#,Database,Arguments,在DataGridView上显示数据时出错 我认为这是相关的-1问题,但我如何处理这3个条件,我无法实现。 当数据计数为3时,没有问题 当数据计数为2或1时,程序会给出类似错误的参数超出范围异常 ... DataTable abc = new DataTable(); sda.Fill(abc); DataGridView.DataSource = abc; if (Convert.ToString(D

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



            ...

什么是
DataGridView.Rows.Count
?在访问它们之前,您应该检查DataGridView.Rows.Count。3尽可能多,但根据我们的组合框选择,它可以是2、1和0。您可以给我一个例子,我在internet上看到一些东西,但无法实现。如果它可以是0 1或2,那么您就不能调用空值上的.cells。如果count=2,DataGridView.Rows[2]将为null,如果为null,则不能调用其上的.Cells。