使用vb.net选择ALL数据库 [英] Select ALL database using vb.net
问题描述
如何在Visual Basic中创建一个组合框,它可以在我的服务器中显示所有数据库?
以及如何过滤它,例如
只显示带有用户表的那些只显示
help pls。并且谢谢!
试试这个:
使用 con 作为 新 SqlConnection(strConnect)
con.Open()
使用 cmd 作为 新 SqlCommand( sp_databases,con)
cmd.CommandType = CommandType.StoredProcedure
< span class =code-keyword> Dim 读取作为 SqlDataReader = cmd.ExecuteReader()
while read.Read()
Console.WriteLine( DirectCast (读取( DATABASE_NAME),字符串))
结束
结束 使用
结束 使用您需要做的就是将信息整理到组合框中。
如果您使用DataView作为Combobox DateSource,您应该能够以正常方式应用过滤器(我没有使用Combobox尝试过它,但它适用于DataGridViews。)
我有问题,我不知道如何根据其中的表格过滤数据库。示例我只想显示内部有user表的数据库。我怎么做?谢谢
您需要依次查询每个数据库。
尝试连接数据库并使用:
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA .TABLES
WHERE TABLE_TYPE = ' BASE TABLE '
或者不指定连接中的数据库:
USE yourDBName; SELECT name FROM sys.Tables
How do I make a combobox in Visual Basic where it can display all the database in my server?
and how do i filter it, for example
only the ones with the table "users" are only shown
help pls. and thanks!
Try this:
Using con As New SqlConnection(strConnect) con.Open() Using cmd As New SqlCommand("sp_databases", con) cmd.CommandType = CommandType.StoredProcedure Dim read As SqlDataReader = cmd.ExecuteReader() While read.Read() Console.WriteLine(DirectCast(read("DATABASE_NAME"), String)) End While End Using End UsingAll you have to do is sort out getting the info into the combobox.
If you use a DataView as the Combobox DateSource, you should be able to apply filters in the normal way (I haven't tried it with a Combobox, but it works fine with DataGridViews.)
"i have a problem, i dont know how to filter databases according to the tables inside them. Example i only want to show databases with the table "user" inside. How do i do that? thanks"
You will need to query each DB in turn.
Try connecting to the DB and using:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
Alternatively without specifying the DB in the connection:
USE yourDBName; SELECT name FROM sys.Tables
这篇关于使用vb.net选择ALL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!