Comma seperated columns

Hi I am trying to use c# to generate a comma separated string of columns for all the columns in a data table. I see commonly used stuff on the forum, but I cant seem to find something that fits this request.

Can someone help me out with what this would look like?


Please try this

String.Join(",",dt.Columns.Cast<DataColumn>().Select(x => x.ColumnName).ToArray())



Please change dt as per your datatable name …May be it is bulkdt or testdt for you


It is using the correct dt which is an argument.

Hi @Cushing_Gregory ,

From the above screenshot we see that it is VB project and not C#.

Try the below with the similarity as in the above post :

String.Join(",",DT.Columns.Cast(Of DataColumn).Select(Function(x)x.ColumnName).ToArray)

Appreciate the help, my eyes are rough this morning. Makes sense the invoke code c# code block ran the code. I will test out and report back.

1 Like