SQL Serverからの読み取り中にこのコードを使用しています。問題は、SQL Serverの結果が何回でもループを実行することです。SQL Serverからの読み取り中に動的ボタンを作成
SqlCommand sqlCmd = new SqlCommand("Select Name from TablesDesigner", con);
SqlDataReader sqlReader = sqlCmd.ExecuteReader();
while (sqlReader.Read())
{
for (int row = 0; row < NUM_ROWS; row++)
{
TableRow tablerow = new TableRow(this);
TableLayout.LayoutParams linearLayoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MatchParent, TableLayout.LayoutParams.MatchParent, 1.0f);
tablerow.LayoutParameters = linearLayoutParams;
table.AddView(tablerow);
for (int col = 0; col < NUM_COLS; col++)
{
int FINAL_COL = col;
int FINAL_ROW = row;
Button btn = new Button(this);
TableRow.LayoutParams linearLayoutParams2 = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.MatchParent, 1.0f);
btn.LayoutParameters = linearLayoutParams2;
btn.Text = sqlReader["Name"].ToString();
tablerow.AddView(btn);
}
}
}
私の結果は以下の通りです:
そして、私の望ましい結果は次のとおりです。私は望ましい結果を得るために、私のループを配置する必要があり
?私は何とかそれを壊すべきですか?
ありがとうございました。
また、2つの行を使用する場合はどうすればよいですか?
。ここでは1つのループしか使用できません。 – shahsani