Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my datatable contans two columns ;

ID Value
----- -------
1 100
2 150

I want to added another column like this ,actually it is come in end of the 2 and 150
row, but I want to start from below preview;

ID Value CourseID
----- ------ ----------
1 100 1
2 150 1

please help me,
pavan
Posted
Updated 10-Sep-11 2:36am
v2
Comments
DaveAuld 10-Sep-11 8:37am    
Sorry you have lost me........I think you want to add a column to the datatable, but you want it to appear before existing columns? can you confirm......

When you add your column, I assume from what you say that it is being inserted after the 2, 150 row as (for example) 3, 200.

If so, then that is not a column - it is a row. You want to add a column to the source of your database, rather than tryign to add it to the table itself.

Probably, your DataTable is loaded or bound to a Database source, to look at adding a column either in the Visual Studio Server Explorer pane, or in the appropriate database management system - Sql Management Studio for MsSql.
 
Share this answer
 
It makes no sense to want to insert a row in a DataTable at a specific location as it is not visible to the user and you can visually place it anywhere you want in the control that you do use to display it as shown here where I am replacing a column in a DataGridView in a WinForms application.

ToDoManager.Controls.DataGridViewImageButtonSaveColumn col = new ToDoManager.Controls.DataGridViewImageButtonSaveColumn();
            dgvLinks.Columns.Insert(0, col);
            dgvLinks.Columns.RemoveAt(1);


but if you must place at a specific location try;
_masterTable.Columns.Add().SetOrdinal(index)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900