1

I've seen C# examples but can not find a way to get the column names from the results of a LINQ SQL query in VISUAL BASIC.

So myLINQ query looks like this:

Dim dbs As New DataClasses1DataContext
Dim s As Table(Of sched) = dbs.GetTable(Of sched)()
Dim sQuery = From sp In s
Where sp.custID = cID
Select sp Order By sp.scheddate

There are 13 fields in the table sched, and I'd like to be able to read off the column names in a foreach type loop. Can anyone help me?

Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
  • Extrapolating from [this answer](http://stackoverflow.com/questions/1803192/linq-get-table-column-names) I'd think something like `var columnNames = dbs.Mapping.MappingSource.GetModel(GetType(DataClasses1DataContext)) .GetMetaType(GetType(sched)).DataMembers` – stuartd Jan 13 '14 at 15:01
  • Why do you need column names? What are you doing with the data once selected? – Mych Jan 13 '14 at 16:00
  • I am populating a datagrid using code like: Dim MyTable As New DataTable Dim dc As DataColumn For Each r In schedNames dc = New DataColumn dc.DataType = System.Type.GetType("System.String") dc.ColumnName = "SID" MyTable.Columns.Add(dc) Next – user3154443 Jan 13 '14 at 17:20
  • So Stuartd answered the question. I just needed to tweak for VB slightly: Dim columnNames = dbs.Mapping.MappingSource.GetModel(GetType(DataClasses1DataContext)).GetMetaType(GetType(sched)).DataMembers THANKS. – user3154443 Jan 13 '14 at 17:34

0 Answers0