Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox1.SelectedValue == null) return;
- string SeaID = comboBox1.SelectedValue.ToString();
- string queryString2 = String.Format("SELECT Id, Area FROM dbo.Area WHERE seaID ='" + SeaID + "'");
- using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=|DataDirectory|ПАК_ИП_ОЭБ_Data.mdf;Integrated Security=True"))
- {
- try
- {
- SqlCommand cmd2 = new SqlCommand(queryString2, connection);
- if (cmd2 != null)
- {
- DataTable tbl2 = new DataTable();
- SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
- da2.Fill(tbl2);
- this.comboBox2.DataSource = tbl2;
- this.comboBox2.DisplayMember = "Area";// столбец для отображения
- this.comboBox2.ValueMember = "Id";//столбец с id
- comboBox2.SelectedIndex = -1;
- comboBox2.Enabled = true;
- }
- else
- {
- MessageBox.Show("1");
- comboBox2.SelectedIndex = -1;
- comboBox2.Enabled = false;
- }
- }
- finally
- {
- if (connection != null)
- {
- connection.Close();
- }
- }
- }
- else
- {
- MessageBox.Show("1");
- comboBox2.SelectedIndex = -1;
- comboBox2.Enabled = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement