get column names from a table in an Access database using VB.NET

前端 未结 1 2013
名媛妹妹
名媛妹妹 2020-12-22 10:33

How can I get all column names from a table in an Access database using VB.NET? With some articles on the Internet that I\'ve tried, the result given is just the database sc

相关标签:
1条回答
  • 2020-12-22 11:00

    You need to pass the name of the collection you are interested in to the GetSchema method. In the case of the columns collection, you also need to pass in an array of strings to filter the returned values.

    Dim connectionString = csb2.ToString
    Dim tableName = "Sales Reports"
    Dim filterValues = {Nothing, Nothing, tableName, Nothing}
    
    Using conn = New OleDbConnection(connectionString)
        conn.Open
        Dim columns = conn.GetSchema("Columns", filterValues)
        For Each row As DataRow In columns.Rows
            Console.WriteLine("{0,-20}{1}",row("column_name"),row("data_type"))
        Next
    End Using
    

    See here.

    0 讨论(0)
提交回复
热议问题