2008/11/30 00:00
DataTable.NewRow General .NET2008/11/30 00:00
private void MakeDataTableAndDisplay() { // Create new DataTable and DataSource objects. DataTable table = new DataTable(); // Declare DataColumn and DataRow variables. DataColumn column; DataRow row; DataView view; // Create new DataColumn, set DataType, ColumnName and add to DataTable. column = new DataColumn(); column.DataType = System.Type.GetType("System.Int32"); column.ColumnName = "id"; table.Columns.Add(column); // Create second column. column = new DataColumn(); column.DataType = Type.GetType("System.String"); column.ColumnName = "item"; table.Columns.Add(column); // Create new DataRow objects and add to DataTable. for(int i = 0; i < 10; i++) { row = table.NewRow(); row["id"] = i; row["item"] = "item " + i.ToString(); table.Rows.Add(row); } // Create a DataView using the DataTable. view = new DataView(table); // Set a DataGrid control's DataSource to the DataView. dataGrid1.DataSource = view; }
'General .NET' 카테고리의 다른 글
| 익명 메서드(Anonymous Methods) (0) | 2008/11/30 |
|---|---|
| Nullable 타입 (0) | 2008/11/30 |
| DataTable.NewRow (0) | 2008/11/30 |
| 닷넷2.0을 시작하며... (0) | 2008/07/22 |
| 세티의 닷넷강좌를 다시 살리겠습니다. (0) | 2008/07/22 |
| 닷넷 전용 어셈블리 (0) | 2008/04/27 |
