Show data from different database in same app c#

  • 300 Views
  • Last Post 21 August 2018
Stylus STYLUS posted this 21 August 2018

I need some help...I have my app MKS

Create database MKS_2017 and using...work fine

Now I create MKS_2018 and using working fine

I need to login to my app with (username, password) and in combobox to chose database to show data in my app (MKS_2017 or MKS_2018)

I read database from server on this way:

public List<string> GetDatabaseList()
        {
            List<string> list = new List<string>();

            using (SqlConnection con = new SqlConnection(cs))
            {
                con.Open();

                // Set up a command with the given query and associate
                // this with the current connection.
                using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases where name like 'MKS%'", con))
                {
                    using (IDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            list.Add(dr[0].ToString());
                        }
                    }
                }
            }
            return list;

        }

 

lucy posted this 21 August 2018

You can see this post to know how to change your connection string at run time

Close