Reputation: 1
I have two combo boxes in my form app. When the form loads I do this:
combobox1.items.add(system.environment.machinename).
Thats works. Now i want to populate the second combo box with the databases of the selected server. How do I do that?
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
????????
}
Upvotes: 0
Views: 83
Reputation:
If you are using SQL Server, you can have database with following query:
SELECT name
FROM sys.databases
You can execute procedure sp_databases
too:
EXEC sp_databases
Upvotes: 0
Reputation: 176896
Try
in .NET you can use the SQL Server Management Objects
Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server("localhost");
foreach (Database db in server.Databases) {
Console.WriteLine(db.Name);
}
Upvotes: 1