private void button1_Click(object sender, EventArgs e)
{
string s=null;
foreach (DataRow a in amDataSet.students.Rows)
{
if (a["id"] > s)
{
s = a["id"].ToString();
}
}
MessageBox.Show(s);
}
答案 0 :(得分:-1)
如果id
是数字类型,您可以尝试DataTable.Compute
:
int max = Convert.ToInt32( amDataSet.students.Compute("max(id)", "") );
或使用Enumerable.Max
LINQ扩展名:
int max = amDataSet.students.Rows.Cast<DatRow>().Max(r => Convert.ToInt32(r["id"]));