Advertisement
Balda

Untitled

Mar 19th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. /// <summary>
  2. /// Заполнение элемента Combobox из БД
  3. /// </summary>
  4. /// <param name="cb">Элемент combobox</param>
  5. /// <param name="cbValueMember">Свойства значения</param>
  6. /// <param name="cbDisplayMember">Свойство отображения</param>
  7. /// <param name="FillerName">Имя хранимой процедуры</param>
  8. /// <param name="FillerTable">Имя таблицы</param>
  9. public static void GetList(ComboBox cb, string cbValueMember, string cbDisplayMember, string FillerName, string FillerTable)
  10. {
  11. using (MySqlConnection Connection = new MySqlConnection(Properties.Settings.Default.DBConnectionString))
  12. {
  13. MySqlCommand cmd = new MySqlCommand(FillerName, Connection);
  14. MySqlDataAdapter da = new MySqlDataAdapter();
  15. DataSet ds = new DataSet();
  16. try
  17. {
  18. cmd.CommandType = CommandType.StoredProcedure;
  19. da.SelectCommand = cmd;
  20. da.Fill(ds, FillerTable);
  21. cb.DataSource = ds.Tables[FillerTable];
  22. cb.DisplayMember = cbDisplayMember;
  23. cb.ValueMember = cbValueMember;
  24. }
  25. catch (Exception)
  26. {
  27. throw;
  28. }
  29. finally
  30. {
  31. cmd.Dispose();
  32. Connection.Close();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement