对DataGridView数据进行查询方法

1.DataGridView转DataTable

2.DataTable转DataView

3.DataView转DataTable

private System.Data.DataTable Get_lcg(DataGridView myDataGridView)
{
System.Data.DataTable mydataTable = new System.Data.DataTable();

System.Data.DataTable dt = ((System.Data.DataTable)myDataGridView.DataSource).Copy();

DataView dv = dt.DefaultView;
dv.RowFilter = string.Format("字段名 = '{0}')","字段查询内容");
mydataTable = dv.ToTable(true, "字段一", "字段二", "字段三");

return mydataTable;
}

转载于:https://www.cnblogs.com/wenlong2019/p/11330566.html

你可能感兴趣的:(对DataGridView数据进行查询方法)