Beispiel #1
0
        private void cmbTables_Click(object sender, EventArgs e)
        {
            if (cmbTables.Items.Count == 0)
            {
                using (GetConnection form = new GetConnection())
                {
                    DialogResult dr = form.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        if (!String.IsNullOrEmpty(Connection.ConnectionString))
                        {
                            SqlConnection cnn;

                            cnn = new SqlConnection(Connection.ConnectionString);
                            cnn.Open();
                            List <string> lstDB = new List <string>();
                            using (SqlCommand cmd = new SqlCommand("select table_name  from " + Connection.Database + ".INFORMATION_SCHEMA.TABLES order by table_name asc", cnn))
                            {
                                using (SqlDataReader dr1 = cmd.ExecuteReader())
                                {
                                    while (dr1.Read())
                                    {
                                        lstDB.Add(dr1[0].ToString());
                                    }
                                }
                            }
                            cnn.Close();
                            // ComboBox combo = new ComboBox();
                            cmbTables.DataSource = lstDB;
                            //combo.Name = "comboBoxTables";
                            //combo.DisplayMember = this.dS.Tables[0].Columns[++_i].ColumnName;
                            // combo.Location = new Point(100, 100);

                            //cmbTables.SelectedIndexChanged +=
                            //new System.EventHandler(ComboBox1_SelectedIndexChanged);
                            // this.Controls.Add(combo);
                        }
                    }
                }
            }
        }