How to add a column in a datatable dynamically....

Posted by Santosh4u under VB.NET on 11/11/2010 | Points: 10 | Views : 8210 | Status : [Member] | Replies : 2
Hi All,

Any body plz tell me ,
how to add a column in a datatable dynamically in any position...


Ex:i have a datatable called(dt) having 3 columns(ID,Name,DOB)
now i want to add a column called(Salary) dynamically in third position, means after id so my final datataable columns should be
like....

ID,Name,salary,DOB

Regards
Santosh




Responses

Posted by: T.saravanan on: 11/11/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Santhosh,

After column adding just use the following code.Here i am give a code in c#.

dt.Columns["Salary"].SetOrdinal(2);


Cheers :)

Thanks,
T.Saravanan

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 11/11/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

try this link will help

http://forums.asp.net/p/1573806/3952211.aspx

LP MER

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response