DataTable dt = new DataTable(); dt = (DataTable)Session["table"]; DataRow[] rows = dt.Select("Name = 'abc'"); dt.Clear(); dt.Rows.Add(rows);
Input array is longer than the number of columns in this table.
if (Session["table"] != null) { DataColumn col = new DataColumn(); col.DataType = System.Type.GetType("System.Int32"); col.ColumnName = "sno"; DataTable dt = new DataTable(); dt = (DataTable)Session["table"]; if (!dt.Columns.Contains("RegNo")) { dt.Columns.Add("RegNo").SetOrdinal(6); } if (!dt.Columns.Contains(col)) { dt.Columns.Add(col); col.SetOrdinal(0); } int index = 0; foreach (DataRow row in dt.Rows) { row.SetField(col, ++index); } DataRow[] rows = dt.Select("Name = 'abc'"); dt.Clear(); if (flag == 0) { foreach (DataRow row in dt.Rows) { row.SetField("RegNo", "null"); } flag = 1; } dt.Rows.Add(rows); gd.Visible = true; gd.DataSource = dt; gd.DataBind(); }
DataRow[] dr = null;//a datarow array dr = dt.Select("Name != 'abc'"); //get the rows with matching condition in arrray //loop throw the array and delete those rows from datatable foreach (DataRow row in dr) { dt.Rows.Remove(row); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)