I have a DataTable with 2 columns in it. I would like to insert another column to the start, and move those 2 columns to the right by 1.
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
Any ideas how I could do this?
Thanks.
I have a DataTable with 2 columns in it. I would like to insert another column to the start, and move those 2 columns to the right by 1.
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
Any ideas how I could do this?
Thanks.
Try this.
DataColumn column = dtCurrentTable.Columns.Add("Column Name", typeof(<<The data type of your column>>));
column.SetOrdinal(0);// to put the column in position 0;
Do Something like this>>
DataTable workTable = new DataTable("Customers");
DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32));
workCol.AllowDBNull = false;
workCol.Unique = true;
workTable.Columns.Add("CustLName", typeof(String));
workTable.Columns.Add("CustFName", typeof(String));
workTable.Columns.Add("Purchases", typeof(Double));
Hope its helpfull.