-3

I just tried to make an application that shows my boks but when i make the page number int, i faced with this IndexOutOfRange error and i can't fix it. Please help...

textBox1.Text = reader["ad"].ToString();
            textBox2.Text = reader.GetInt32(4).ToString();
  • 1
    The error says the index you are using is out of range for the list. reader.GetInt32 dont have element number 4. please remember that index starts from zero. – Abbas Dehghan Mar 02 '19 at 08:04
  • I rekon `reader` is an SQL query reader, but can you provide more code, so we can see what the `reader` is and where you get it from? – Max Mar 02 '19 at 08:08
  • Possible duplicate of [What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?](https://stackoverflow.com/questions/20940979/what-is-an-indexoutofrangeexception-argumentoutofrangeexception-and-how-do-i-f) –  Mar 02 '19 at 08:18

1 Answers1

1

You can check

if(!reader.IsDBNull(4)){
 textBox2.Text = reader.GetInt32(4).ToString();
}
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62