private DataTable GetNewDataTable(DataTable dt,string condition)
{
DataTable newdt = new DataTable();
newdt=dt.Clone();
DataRow[] dr = dt.Select(condition);
for(int i=0;i<dr.Length;i++)
{
newdt.ImportRow((DataRow)dr[i]);
}
return newdt;//返回的查询结果
}
调用:
string strFilter = string.Empty;
strFilter = " " + strID + " like '%" + textBox1.Text + "%' or " + strName + " like '%" + textBox1.Text + "%' ";
DataTable dtDes = GetNewDataTable(dtSrc, strFilter);
bindingSource2.DataSource = dtDes;
dataGridView2.DataSource = bindingSource2;