Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
[no name] 13-Sep-12 10:24am    
Maybe you could improve your question with some information that "anyone" could use to help you. What database? What have you tried?
ZurdoDev 13-Sep-12 10:50am    
Assuming you are using SQL you could start out with something like SELECT * FROM master.dbo.sysdatabases Is that the information you are looking for?
Zoltán Zörgő 15-Sep-12 4:52am    
Any progress?

query db with

SQL
SELECT [name]
FROM master.dbo.sysdatabases
WHERE dbid > 4


and show the information in combobox
 
Share this answer
 
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[^])

C#
...
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());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900