Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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# IndexOutOfRangeException我如何修复它_C#_Visual Studio_Datagridview_Indexoutofrangeexception - Fatal编程技术网

C# IndexOutOfRangeException我如何修复它

C# IndexOutOfRangeException我如何修复它,c#,visual-studio,datagridview,indexoutofrangeexception,C#,Visual Studio,Datagridview,Indexoutofrangeexception,我只是尝试制作一个显示我的知识的应用程序,但是当我将页码设置为int时,我遇到了这个indexoutfrange错误,我无法修复它。请帮忙 textBox1.Text = reader["ad"].ToString(); textBox2.Text = reader.GetInt32(4).ToString(); 你可以查一下 if(!reader.IsDBNull(4)){ textBox2.Text = reader.GetInt32(4).ToString();

我只是尝试制作一个显示我的知识的应用程序,但是当我将页码设置为int时,我遇到了这个indexoutfrange错误,我无法修复它。请帮忙

textBox1.Text = reader["ad"].ToString();
            textBox2.Text = reader.GetInt32(4).ToString();
你可以查一下

if(!reader.IsDBNull(4)){
 textBox2.Text = reader.GetInt32(4).ToString();
}

错误表示您使用的索引超出列表的范围。reader.GetInt32没有元素编号4。请记住索引从零开始。我rekon reader是一个SQL查询阅读器,但是你能提供更多的代码吗,这样我们就可以看到阅读器是什么,从哪里得到它?可能是