2007/12/17 10:26
DataTable.NewRow General .NET2007/12/17 10:26
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' 카테고리의 다른 글
| VSTO - Word Automation (0) | 2007/12/17 |
|---|---|
| Socket Class (0) | 2007/12/17 |
| DataTable.NewRow (0) | 2007/12/17 |
| int.Parse(int value)와 Convert.ToInt(object value)와의 차이점 (0) | 2007/12/17 |
| 닷넷 전용 어셈블리 (0) | 2007/12/17 |
| 델리게이트 (0) | 2007/12/17 |
TAG DataTable.NewRow
