How to get The name of Columns RRS feed

  • Question

  • Does anybody know how to get the name of Columns of a table  and add them in a checklistbox ??
    My code is here :

    Dim myconn As OleDbConnection
                    Dim ConnectionString As String
                    ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & TextPath.Text
                    myconn = New OleDb.OleDbConnection(ConnectionString)
                    Dim strSQL As String = "SELECT * FROM @checkeditem"

                    Dim myCmd As New OleDbDataAdapter(strSQL, myconn)
                    Catch ex As Exception
                        MsgBox("Something is not right")
                    End Try

                    Dim dtSet As New DataSet

                    myCmd.Fill(dtSet, "@nameoftable")              'this line is not working

                    Dim dt As DataTable = dtSet.Tables(0)
                    Dim dc As DataColumn

                    For Each dc In dt.Columns
                    Next dc

    Friday, November 16, 2012 12:04 AM


  • From something I posted the other day:

    Dim cList As New List(Of String) ' For Each column As DataColumn In ContactsDataSet.People.Columns cList.Add(column.ColumnName) Next

    Please call me Frank :)

    • Proposed as answer by Cor Ligthert Friday, November 16, 2012 12:35 AM
    • Marked as answer by Mark Liu-lxf Wednesday, November 28, 2012 7:44 AM
    Friday, November 16, 2012 12:14 AM