Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.9k

Show data from diferent database in same app c#

Aug 21 2018 1:33 AM

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 when login in my app to using (username,password) and in combox to chose database data to show in my app (MKS_2017 or MKS_2018)

I read database from server on this way:

 
  1. public List<string> GetDatabaseList()  
  2.         {  
  3.             List<string> list = new List<string>();  
  4.              
  5.             using (SqlConnection con = new SqlConnection(cs))  
  6.             {  
  7.                 con.Open();  
  8.   
  9.                 // Set up a command with the given query and associate  
  10.                 // this with the current connection.  
  11.                 using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases where name like 'MKS%'", con))  
  12.                 {  
  13.                     using (IDataReader dr = cmd.ExecuteReader())  
  14.                     {  
  15.                         while (dr.Read())  
  16.                         {  
  17.                             list.Add(dr[0].ToString());  
  18.                         }  
  19.                     }  
  20.                 }  
  21.             }  
  22.             return list;  
  23.   
  24.         } 
 

Answers (3)