DATATABLE, DATACOLUMN AND DATAROW OBJECT
• DataTable object represents one table of in-memory data
• Mostly used as a container of data within a DataSet, the DataTable object is also valid as a standalone object that contains tabular data
• To create a DataTable programatically, first define its schema and then add new rows
• Using DataColumn define Columns within a DataTable
• Sample code : DataSet > DataTable > DataColumn > DataRow
----------CREATING A DataTable WITHIN A DATASET-------------
DataSet ds = new DataSet();
DataTable tableEmp = new DataTable(“Employees”);
-----------CREATING A DataColumn WITHIN A DATATABLE-----------------
DataColumn dcol = new DataColumn();
dcol.DataType = System.Type.GetType("System.Decimal");
dcol.AllowDBNull = true; dcol.Caption = "Salary"; dcol.ColumnName = "Salary";
dcol.DefaultValue = 0;
tableEmp.Columns.Add(dcol);
-------------CREATING DataRow WITHIN A DATATABLE--------------------
DataRow row = tableEmp.NewRow();
row[“ID”] = 1;
row[“Name”] = ”Bubbly”;
tableEmp.Rows.Add(row);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment