如何根据所选数据库获取所有表 [英] how to fetch all the tables depending on selected database

查看:77
本文介绍了如何根据所选数据库获取所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



i有一个组合框,我选择服务器中存在的数据库名称。现在我想要在选择数据库时它应该加载所有下一个组合框中数据库的表格。



请告诉我该怎么做



谢谢你

解决方案

使用此查询来获取相应的数据库表。



onSelectedIndexChange组合事件运行此查询并获取输出



从information_schema.tables中选择table_name

其中table_catalog =''数据库名称''和table_type =''BASE TABLE''


查询...

  USE  < U> DBNAME ;  SELECT  TABLE_NAME  FROM  INFORMATION_SCHEMA.TABLES  WHERE  TABLE_TYPE = '  BASE TABLE' 





cmbDBList.Text的传递值代替查询中的DBNAME



快乐编码!

:)


您好,



请阅读[ ^ ]这篇文章。以下是同一篇文章的摘录。

  Sub  Main()
Dim connectionString 作为 字符串 = 将您的连接绳子放在这里
使用连接< span class =code-keyword> As SqlConnection(connectionString)
' 连接到数据库,然后检索架构信息。
connection.Open()
Dim table As DataTable = connection.GetSchema(
// 每个行代表单个
// 对于 SQL Server 每个行将有四个列,即table_catalog,table_schema,table_name table_type
对于 每个 As DataRow table.Rows
对于 每个 col 作为 DataColumn table.Columns
Console.WriteLine( {0} = {1 },col.ColumnName,row(col))
下一步
下一步
结束 使用
结束 Sub



问候,


Hi all

i have one combo box where i am selecting the database name present in a server.now i want when i am selecting the database it should load all the tables of the database at next combo box.

Please tell me how to do that

Thank you

解决方案

Use this query to get respective table of database.

onSelectedIndexChange event of combo run this query and get your output

select table_name from information_schema.tables
where table_catalog = ''DataBase Name'' and table_type = ''BASE TABLE''


Query...

USE DBNAME; SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'



Pass value of cmbDBList.Text in place of DBNAME in query

Happy Coding!
:)


Hello,

Please read[^] this article. Below is an excrept from the same article.

Sub Main()
    Dim connectionString As String = "PUT YOUR CONNECTION STRING HERE"
    Using connection As New SqlConnection(connectionString)
        'Connect to the database then retrieve the schema information.
        connection.Open()
        Dim table As DataTable = connection.GetSchema("Tables")
        // Each row represents a single table
        // For SQL Server each row will have four columns namely table_catalog, table_schema, table_name and table_type
        For Each row As DataRow In table.Rows
            For Each col As DataColumn In table.Columns
                Console.WriteLine("{0} = {1}", col.ColumnName, row(col))
            Next
        Next
    End Using
End Sub


Regards,


这篇关于如何根据所选数据库获取所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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