在组合框中显示数据库名称 [英] Display database name in combobox
本文介绍了在组合框中显示数据库名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在文本框中输入我的系统名称后,如何在组合框(我现在正在使用)中显示当前系统数据库列表.有人可以帮助我吗?
How to display current system Database list in combobox(which i am using now) after entering my system name in Textbox.Can anyone help me?
推荐答案
query具有
的数据库
query db with
SELECT [name]
FROM master.dbo.sysdatabases
WHERE dbid > 4
并在组合框中显示信息
and show the information in combobox
假设使用SQL Server,则可以使用管理对象枚举指定服务器实例的数据库. (请参阅: http://msdn.microsoft.com/en -us/library/microsoft.sqlserver.management.smo.server.databases.aspx [
Assuming SQL Server, you can use the management objects to enumerate the databases of a specified server instance. (See: http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.databases.aspx[^])
...
using Microsoft.SqlServer.Management.Smo;
...
Server sr = new Server("MACHINE_NAME\\INSTANCE_NAME");
try
{
DbCombo.Items.Clear();
foreach (Database db in sr.Databases)
{
DbCombo.Items.Add(db.Name);
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.ToString());
}
这篇关于在组合框中显示数据库名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文