所以我有一个非常简单的函数,它遍历一个表,找到那些年龄列在2个数字之间的行,然后返回一个包含新行的新表。这是我的功能:
private DataTable AgeFinder(int MiniAge, int MaxiAge, DataTable x)
{
//AFWT : Analyze From Which Table
int count;
DataTable dtAge = new DataTable();
dtAge = x.Clone();
int ageMin = MiniAge;
int ageMax = MaxiAge;
if (ageMin > ageMax)
{
int temp = ageMax;
ageMax = ageMin;
ageMin = temp;
}
int ageDr;
count = 0;
ageDr = 0;
dataGridView1.DataSource = x;
foreach (DataRow dr in x.Rows)
{
ageDr = Convert.ToInt16(x.Rows[count]["age "]);
if (ageDr >= ageMin && ageDr < ageMax)
{
dtAge.Rows.Add(dr.ItemArray);
}
count++;
}
lblCountThisQuery.Text = dtAge.Rows.Count.ToString();
return dtAge;
}
以下是我的称呼方式:
dtAge = AgeFinder(Convert.ToInt16(tbxMinAge.Text), Convert.ToInt16(tbxMaxAge.Text), AT);
dataGridView1.DataSource = dtAge;
现在我可以看到AT不是空的但是当我检查x(方法内的表)时,它是空的!为什么会这样?