Guest User

Untitled

a guest
Feb 21st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. void fill_listbox()
  2. {
  3. string constring = "datasource=localhost;port=3306;username=root;password=xdmemes123";
  4. string Query = "select * from life.players ;";
  5. MySqlConnection conDataBase = new MySqlConnection(constring);
  6. MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
  7. MySqlDataReader myReader;
  8. try
  9. {
  10. conDataBase.Open();
  11. myReader = cmdDataBase.ExecuteReader();
  12.  
  13. while (myReader.Read())
  14. {
  15. string sName = myReader.GetString("name");
  16. namelistbox.Items.Add(sName);
  17. }
  18. }catch (Exception ex)
  19. {
  20. MessageBox.Show("Something went wrong. Error copied to clipboard.");
  21. Clipboard.SetText(ex.Message);
  22. }
  23. }
  24.  
  25. List<string> playerNames;
  26.  
  27. void fill_listbox()
  28. {
  29. string constring = "datasource=localhost;port=3306;username=root;password=xdmemes123";
  30. string Query = "select * from life.players ;";
  31. MySqlConnection conDataBase = new MySqlConnection(constring);
  32. MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
  33. MySqlDataReader myReader;
  34. try
  35. {
  36. conDataBase.Open();
  37. myReader = cmdDataBase.ExecuteReader();
  38.  
  39. while (myReader.Read())
  40. {
  41. string sName = myReader.GetString("name");
  42. playerNames.Add(sName);
  43. }
  44.  
  45. foreach(string name in playerNames)
  46. {
  47. namelistbox.Items.Add(name);
  48. }
  49.  
  50. }catch (Exception ex)
  51. {
  52. MessageBox.Show("Something went wrong. Error copied to clipboard.");
  53. Clipboard.SetText(ex.Message);
  54. }
  55. }
  56.  
  57. void textBox_TextChanged(object sender, EventArgs e)
  58. {
  59. // create filtered list from playerNames
  60. var filteredList = from name in playerNames
  61. where CultureInfo.CurrentCulture.CompareInfo.IndexOf(name, textBox.Text, CompareOptions.IgnoreCase) >= 0
  62. select name;
  63.  
  64. namelistbox.Items.Clear();
  65. foreach (string name in filteredList)
  66. namelistbox.Items.Add(name);
  67. }
Add Comment
Please, Sign In to add comment