.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to add a column a in datatable at defined position

Posted By: Santosh     Posted Date: June 06, 2011    Points:5   Category :VB.Net
hi

can anybody plz tell me,how to add a column/row at the defined position...

Ex: let say i have a datatable contains 10 columns stating from id,name etc..
but i wnat to add a new empty column as (slno) before the the id column and not the datatable will be slno.id,name etc.......


same like row i want add some null row from index 0 ....



regards
santosh

Responses
Author: Gowthammanju             
Posted Date: June 06, 2011     Points: 20   

please try the above links u will able to solve ur poblem


http://msdn.microsoft.com/en-us/library/hfx3s9wd.aspx
http://www.thescarms.com/dotnet/AddColumns.aspx
http://www.velocityreviews.com/forums/t81356-adding-a-column-to-a-datatable.html


or use ur code as

 Dim adc1 As DataColumn
Dim adc2 As DataColumn


adc1 = New DataColumn("Name", System.Type.GetType("System.Decimal"))
adc2 = New DataColumn("No", System.Type.GetType("System.Int32"))

DS.Tables("sample").Columns.Add(adc1)
DS.Tables("sample").Columns.Add(adc2)






Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Santosh             
Posted Date: June 06, 2011     Points: 20   

hi Gowthammanju

i think u have not clear about mt doubt...
i know how to add column but i want to add column in a spcific position in a datatble...


reagards
santosh

Author: shiv chandra             
Posted Date: June 07, 2011     Points: 20   

Hi Santosh,
Can you please let me know, why you need to add column at specific position in datatable.
Please explain your requirement clearly.


Reagrds,
Shiva


Regards
Shiva
Author: seattlegirl             
Posted Date: June 07, 2011     Points: 20   

Try using the SetOrdinal method of DataColumn.

Author: SureshM             
Posted Date: June 08, 2011     Points: 20   


Hi santhosh

You can add a column in the desired position Like this

dst.Tables[0].Columns["Colname"].SetOrdinal(1);

And you can add a row like this

dst.Tables[0].Rows.InsertAt(DataRow,position)

i hope this will help u..

Author: Narayanan             
Posted Date: July 25, 2011     Points: 20   

http://www.dotnetspider.com/forum/287807-How-add-column-datatable-at-defined-position.aspx

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend