显示来自数据库(MS Access)的数据,我希望在所选数据的末尾显示另一个表格。我试过如果使用循环如何使用C#显示数据库的下一个数据?
private void btnNext_Click(object sender, EventArgs e) //**This will select the next row**
{
currentRow++;
nextRow();
}
private void nextRow()
{
if (currentRow <= n)
{ //**Randomize the RadioButtons.Text**
var row = dTable.Rows[currentRow];
List<string> list = new List<string> { row["C1"].ToString(), row["C2"].ToString(), row["C3"].ToString(), row["C4"].ToString() };
lblQuest.Text = row["QUESTION"].ToString();
btn1.Text = row["C1"].ToString();
btn2.Text = row["C2"].ToString();
btn3.Text = row["C3"].ToString();
btn4.Text = row["C4"].ToString();
var ans = row["ANSWER"].ToString();
var rbtn = new[] { btn1, btn2, btn3, btn4 };
var rnd = new Random();
var shuffTxt = list.OrderBy(x => rnd.Next(list.Count)).ToList();
for (int i = 0; i < rbtn.Length; i++)
{
rbtn[i].Text = shuffTxt[i];
}
}
if (currentRow > n)
{ //**If the currentRow is already greater than the n selected rows, it will display a form**
frmPIPE frm = new frmPIPE();
frm.Show();
Hide();
}
}
但是当currentRow > n
;它显示一个错误
“没有排位置n”
你的意思是'frmPIPE frm = new frmPIPE();'这一行会引发这个错误?! )。即使没有该代码,也可以使用 –
。当currentRow大于行数时会产生错误。 –
at var row = dTable.Rows [currentRow]; –