Two database:
1) 2017 (table name partners(id, name))
2) 2018 (table name partners(id, name))
On Form 1 have username, password, button login and combo box.
On Form 2 empty partnerdatagrid
I need when in combobox chose value 2017 show data from database 2017 (table name partners(id, name)),
if choose value 2018 to show data from 2018 (table name partners(id, name))
Some help?
Combobox value are find on next way
- InitializeComponent();
- comboBox1.DataSource = GetDatabaseList();
- 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 '20%'", con))
- {
- using (IDataReader dr = cmd.ExecuteReader())
- {
- while (dr.Read())
- {
- list.Add(dr[0].ToString());
- }
- }
- }
- }
- return list;
- }

Suraj KumarRank #353 · 7.1K reputationPosted Sep 4, 2018, 10:00 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Sep 4, 2018, 9:57 AM EDT
Goran BibicRank #993 · 2K reputationPosted Sep 4, 2018, 10:06 AM EDT
Goran BibicRank #993 · 2K reputationPosted Sep 4, 2018, 10:11 AM EDT