DataTable table = new DataTable();
table.Columns.Add("EmpID", typeof(int));
table.Columns.Add("EmpName", typeof(string));
table.Columns.Add("EmpAge", typeof(int));
table.Columns.Add("DOB", typeof(DateTime));
//auto increment column
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
table.Columns.Add(column);
//Add Values to DataTables
table.Rows.Add(1, "Mohamed", 27, new DateTime (1986,05,06));
table.Rows.Add(2, "sithik", 26,new DateTime (1986,08,11));
table.Rows.Add(10, "Raja", 25,new DateTime(1985,12,05));
table.Rows.Add(11, "uthaya",30,new DateTime(1983,10,10));
table.Rows.Add(12, "Ela", 28,new DateTime (1985,12,23));
DataView view = new DataView(table);
DataRow[] result = table.Select("EmpAge >= 20 AND EmpName = 'sithik'");
DataTable dt1 = result.CopyToDataTable();
DataView view = new DataView(table);
view.RowFilter = "DOB > #1/1/1986#";
view.Sort = "EmpAge Desc";
table.Columns.Add("EmpID", typeof(int));
table.Columns.Add("EmpName", typeof(string));
table.Columns.Add("EmpAge", typeof(int));
table.Columns.Add("DOB", typeof(DateTime));
//auto increment column
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.AutoIncrement = true;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
table.Columns.Add(column);
//Add Values to DataTables
table.Rows.Add(1, "Mohamed", 27, new DateTime (1986,05,06));
table.Rows.Add(2, "sithik", 26,new DateTime (1986,08,11));
table.Rows.Add(10, "Raja", 25,new DateTime(1985,12,05));
table.Rows.Add(11, "uthaya",30,new DateTime(1983,10,10));
table.Rows.Add(12, "Ela", 28,new DateTime (1985,12,23));
DataView view = new DataView(table);
DataRow[] result = table.Select("EmpAge >= 20 AND EmpName = 'sithik'");
DataTable dt1 = result.CopyToDataTable();
DataView view = new DataView(table);
view.RowFilter = "DOB > #1/1/1986#";
view.Sort = "EmpAge Desc";
No comments:
Post a Comment