manually create and fill DataTable
Published: 14. December 2008 | Updated: 26. October 2011License: Microsoft Public License (MS-PL)
Categories: Databases, Winforms
Tags: C# SQL Webforms Winforms WPF
Import namespace
using System.Data;
Code
DataTable table = new DataTable(); DataColumn column; column = table.Columns.Add(); column.ColumnName = "id"; column.DataType = typeof(Guid); column = table.Columns.Add(); column.ColumnName = "name"; column.DataType = typeof(string); column = table.Columns.Add(); column.ColumnName = "age"; column.DataType = typeof(int); DataRow row; row = table.NewRow(); row["id"] = Guid.NewGuid(); row["name"] = "Richard"; row["age"] = 45; table.Rows.Add(row); row = table.NewRow(); row["id"] = Guid.NewGuid(); row["name"] = "Denisa"; row["age"] = 38; table.Rows.Add(row);
| Send us feedback about this snippet » |





