0 votes
1 view
in SQL by (22.4k 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.3k 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
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...