나는 usercontrol (usercontrol2)을 만들고 usercontrol (usercontrol2)에 textBox를 추가합니다.각 컨트롤의 텍스트 상자에 각 레코드 표시
양식 코드 : 내 테이블 (20 개) 기록을 포함하고 있기 때문에 위의 코드와
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select LastName from Employee", myDatabaseConnection))
using (SqlDataAdapter da = new SqlDataAdapter(SqlCommand))
{
SqlDataReader DR1 = SqlCommand.ExecuteReader();
int y = 0;
while (DR1.Read())
{
y++;
for (int i = 0; i < y; i++)
{
UserControl2 userconrol = new UserControl2();
userconrol.Location = new Point(50, 30 * i);
userconrol.Tag = i;
this.Controls.Add(usercontrol);
}
}
}
}
은 내 양식 20에 추가 된 UserControls를 표시합니다.
이제 각 usercontrols '텍스트 상자에 각 성을 표시하는 방법은 무엇입니까?
데이터베이스에있는 성 필드의 이름은 무엇입니까? '(문자열) DR1 [ "LastName"]'예를 들어 .. usercontrol.text 필드 속성에 할당합니다. for 루프 내부에서 DR1을 캡처하지 않습니다. While 루프 내부에서 수행합니다. – MethodMan
성 ... –