Programming Language/C#
DataTable 데이터 복제
하루y
2020. 6. 3. 01:14
private void button1_Click(object sender, EventArgs e)
{
DataTable table = (DataTable) dataGridView1.DataSource;
// 방법1. 구조 및 전체 데이터 복제 후, filter and sort
DataTable table2 = table.Copy();
table2.DefaultView.RowFilter = "구분 = '사용중'";
table2.DefaultView.Sort = "ID DESC";
dataGridView2.DataSource = table2;
}
private void button1_Click(object sender, EventArgs e)
{
DataTable table = (DataTable) dataGridView1.DataSource;
// 방법2. 원본에서 필요한 데이터만 복사.
// DataTable table2 = table.Clone(); // Clone은 구조만 복사됨.
DataRow[] rows = table.Select("구분 = '사용중'", "ID DESC");
DataTable table2 = rows.CopyToDataTable<DataRow>();
dataGridView2.DataSource = table2;
}
728x90