Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  2. {
  3. if (comboBox1.SelectedValue == null) return;
  4. string SeaID = comboBox1.SelectedValue.ToString();
  5. string queryString2 = String.Format("SELECT Id, Area FROM dbo.Area WHERE seaID ='" + SeaID + "'");
  6. using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=|DataDirectory|ПАК_ИП_ОЭБ_Data.mdf;Integrated Security=True"))
  7. {
  8. try
  9. {
  10. SqlCommand cmd2 = new SqlCommand(queryString2, connection);
  11. if (cmd2 != null)
  12. {
  13. DataTable tbl2 = new DataTable();
  14. SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
  15. da2.Fill(tbl2);
  16. this.comboBox2.DataSource = tbl2;
  17. this.comboBox2.DisplayMember = "Area";// столбец для отображения
  18. this.comboBox2.ValueMember = "Id";//столбец с id
  19. comboBox2.SelectedIndex = -1;
  20. comboBox2.Enabled = true;
  21. }
  22. else
  23. {
  24. MessageBox.Show("1");
  25. comboBox2.SelectedIndex = -1;
  26. comboBox2.Enabled = false;
  27. }
  28. }
  29. finally
  30. {
  31. if (connection != null)
  32. {
  33. connection.Close();
  34. }
  35. }
  36.  
  37. }
  38.  
  39. else
  40. {
  41. MessageBox.Show("1");
  42. comboBox2.SelectedIndex = -1;
  43. comboBox2.Enabled = false;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement