re-order columns in a DataTable

Hi all,

I was wondering if there is an easy way to re-order the DataColumns in a DataTable.

Thanks,

Mark.

[130 byte] By [spanky4_3] at [2007-12-25]
# 1
re-order them in what way? Sorting them?
ahmedilyas at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
spanky4_3 wrote:

Hi all,

I was wondering if there is an easy way to re-order the DataColumns in a DataTable.

Thanks,

Mark.

Hi,

Use the setOrdinal method of the datacolumn. It would ask for the new position in the collection...

datatable.Columns["Col1"].SetOrdinal(1);

cheers,

Paul June A. Domag

PaulDomag at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3

Thanks for that Paul it worked perfectly.

Also sorry ahmedilyas that my question was a little vague. I only wanted to shift the index order of the columns in a DataTable. For example, if I had a DataTable with columns col1, col2 & col3 (in that order) I wanted to know how to re-order them to col2, col3 & col1.

Regards,

Mark.

spanky4_3 at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4
no worries - thanks Paul for that, learnt something over here too!
ahmedilyas at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 5

I m facing same problem can i get the solution.

Milan

MilanWarik at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified