Click here to Skip to main content
15,914,408 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
private void Form1_Load(object sender, EventArgs e)
        {

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable table = instance.GetDataSources();
            cboservers.DataSource = table;
            cboservers.DisplayMember = "ServerName";
            
        }
//i want to get the database names into an other combobox when i select servername
Posted

1 solution

Try:
C#
using (SqlConnection con = new SqlConnection(@"Data Source=GRIFFPC\SQLEXPRESS;Integrated Security=True"))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("sp_databases", con))
        {
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataReader read = cmd.ExecuteReader();
        while (read.Read())
            {
            Console.WriteLine((string)read["DATABASE_NAME"]);
            }
        }
    }
That will list the databases on a single server.
 
Share this answer
 
Comments
jacobjohn196 30-Apr-13 2:30am    
Thanx OriginalGriff
OriginalGriff 30-Apr-13 2:38am    
You're welcome!

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