我有一个名为拷贝号的专栏,其中只包含如下数字:
copy number
1
33
12
40
100
如何在 1 和 100 之间获取行?此示例中的范围是行(33,12,40)?
我的数据来自mysql数据库,GridView的填充方式如下:
MySqlDataAdapter a = new MySqlDataAdapter(query, conn)
DataTable t = new DataTable();
a.Fill(t);
dataGridView1.DataSource = t;
PS :非常感谢代码中的答案!
答案 0 :(得分:1)
您可以尝试深入研究文章"BindingSource.Filter Property" on MSDN
根据那里的信息,我会尝试对你的代码执行此操作:
// your original starter code
MySqlDataAdapter a = new MySqlDataAdapter(query, conn)
DataTable t = new DataTable();
a.Fill(t);
// Create a seperate bindingsource object you can control
var bindingSource = new BindingSource();
bindingSource.DataSource = t;
// Now sort on a column
bindingSource.Filter = "[copy number] >= 1 AND [copy number] <= 100";
// Assign that bindingsource object to the dgv
dataGridView1.DataSource = bindingSource;
您可能希望将列名称copy number
修改为cn
或copy_number
,我在此处添加了[]
括号,因为它是the way you can overcome it