Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

Hey, I keep getting an error:

Index (zero-based) must be greater than or equal to zero and less than the size of the argument list.

My code:

OdbcCommand cmd = new OdbcCommand("SELECT FirstName, SecondName, Aboutme FROM User WHERE UserID=1", cn);

OdbcDataReader reader = cmd.ExecuteReader();

while (reader.Read())


    Name.Text = String.Format("{0} {1}", reader.GetString(0), reader.GetString(1));

    Aboutme.Text = String.Format("{2}", reader.GetString(0));


1 Answer

0 votes
by (40.7k points)

In this case, second String.Format is using {2} as the placeholder but you're only passing it in one argument, therefore you should use {0} instead.

Try changing this line of code:

String.Format("{2}", reader.GetString(0));

To this code:

String.Format("{0}", reader.GetString(2));

Related questions

0 votes
1 answer
asked Oct 5, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories