使用VB.NET从Access数据库中的表中获取列名 [英] get column names from a table in an Access database using VB.NET

查看:549
本文介绍了使用VB.NET从Access数据库中的表中获取列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VB.NET从Access数据库的表中获取所有列名? 在Internet上我尝试过的一些文章中,给出的结果只是数据库模式. 有什么解决办法吗?

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 schema. Is there any solution for this?

推荐答案

您需要将感兴趣的集合的名称传递给GetSchema方法.对于column集合,还需要传递一个字符串数组来过滤返回的值.

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

请参见此处.

这篇关于使用VB.NET从Access数据库中的表中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆