Mã bạn có thể làm giảm các cột từ một đối tượng bảng dữ liệu. Những gì mã của tôi làm là nó sẽ lặp qua các đối tượng bảng dữ liệu và sau đó loại bỏ các cột từng cái một.
String strcolname = "";
int i=0;
//Get Data for the reader object
using (reader = cmd.ExecuteReader())
{
// Load the Data table object
dataTable.Load(reader);
//Loop thorough the DataTable object
for (i=dataTable.Columns.Count-1;i>=0;i--)
{
/*
To be more precise , specify the column name you dont want to get deleted,
(you can add multilple column names here)*/
strcolname = dataTable.Columns[i].ColumnName.ToString();
if (strcolname != "ABCD")
{
dataTable.Columns.RemoveAt(i);
}
}
}
Nguồn
2015-02-06 11:01:24
Bạn có tham gia dữ liệu không? – PostMan
có thể trùng lặp: https://stackoverflow.com/questions/75123/remove-columns-from-datatable-in-c-sharp –
có thể trùng lặp: https://stackoverflow.com/questions/75123/remove-columns-từ -datatable-in-c-sharp –