반응형
인덱스 (0 기준)는 0보다 크거나 같아야합니다.
계속해서 오류가 발생합니다.
인덱스 (0 기준)는 0보다 크거나 같고 인수 목록의 크기보다 작아야합니다.
내 코드 :
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));
}
두 번째 String.Format
는 {2}
자리 표시 자로 사용되지만 하나의 인수 만 전달하므로 {0}
대신 사용해야 합니다.
이것을 변경하십시오 :
String.Format("{2}", reader.GetString(0));
이에:
String.Format("{0}", reader.GetString(2));
이 줄에서 :
Aboutme.Text = String.Format("{2}", reader.GetString(0));
매개 변수에 항목이 하나만 있으므로 {2} 토큰이 유효하지 않습니다. 대신 사용 :
Aboutme.Text = String.Format("{0}", reader.GetString(0));
이 줄을 변경하십시오.
Aboutme.Text = String.Format("{0}", reader.GetString(0));
이는 ArgumentException
실수로 ArgumentException
생성자 오버로드를 호출 하는 위치 를 던지려고 할 때도 발생할 수 있습니다.
public static void Dostuff(Foo bar)
{
// this works
throw new ArgumentException(String.Format("Could not find {0}", bar.SomeStringProperty));
//this gives the error
throw new ArgumentException(String.Format("Could not find {0}"), bar.SomeStringProperty);
}
String.Format은 다음과 같이 인덱스 "{0}"0으로 시작해야합니다.
Aboutme.Text = String.Format("{0}", reader.GetString(0));
using System;
namespace ConsoleApp1
{
class Program
{
static void Main()
{
Console.WriteLine("Enter Your FirstName ");
String FirstName = Console.ReadLine();
Console.WriteLine("Enter Your LastName ");
String LastName = Console.ReadLine();
Console.ReadLine();
Console.WriteLine("Hello {0}, {1} " + FirstName, LastName);
Console.ReadLine();
}
}
}
참고 URL : https://stackoverflow.com/questions/5316409/index-zero-based-must-be-greater-than-or-equal-to-zero
반응형
'program tip' 카테고리의 다른 글
이미 업로드 된 Lambda 함수 다운로드 (0) | 2020.08.13 |
---|---|
Google Maps API v3 : 마커 아이콘을 어떻게 동적으로 변경하나요? (0) | 2020.08.13 |
자바에서 .mp3 및 .wav를 재생 하시겠습니까? (0) | 2020.08.13 |
PHP에서 $$ (달러 또는 더블 달러)는 무엇을 의미합니까? (0) | 2020.08.13 |
접미사 a ++와 접두사 ++ a에 대해 두 가지 다른 방법으로 operator ++를 오버로드하는 방법은 무엇입니까? (0) | 2020.08.13 |