我想使用DataView检索DataGridView中的记录。例如,我想检索年龄在15到18岁之间的学生的记录。我该怎么做?下面是我的代码,仅使用DataView检索单个记录:
dgvReport.DataSource = new DataView(dt, "StudentID = " + txtSearch.Text, "StudentID", DataViewRowState.CurrentRows);
任何帮助将不胜感激。谢谢。
答案 0 :(得分:0)
您可以将RowFilter属性用于此
DataView dataView = new DataView(dt);
dataView.RowFilter = "age > 14 and age < 19";
dgvReport.DataSource = dataView;
您将获得年龄从15开始到18
结束的行