Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.OleDb;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApplication2
  13. {
  14. public partial class Teilnehmeranzeigen : Form
  15. {
  16. private static string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=H:\\vs\\WindowsFormsApplication2\\WindowsFormsApplication2\\TeilnehmerITB731.mdb";
  17.  
  18. public Teilnehmeranzeigen()
  19. {
  20. InitializeComponent();
  21. //CreateCommand("Select count(*) from Teilnehmer;", connectionString);
  22. CreateTeilnehmerlist(connectionString);
  23. LabelText(connectionString);
  24. }
  25. private void CreateTeilnehmerlist(string connectionString)
  26. {
  27. try
  28. {
  29. using (OleDbConnection connection = new OleDbConnection(connectionString))
  30. {
  31. connection.Open();
  32. OleDbCommand dataCommand = connection.CreateCommand();
  33. dataCommand.Connection = connection;
  34. dataCommand.CommandText = "SELECT Vorname + ' ' + Name AS Teilnehmername FROM Teilnehmer ORDER BY Name";
  35. OleDbDataReader dataReader = dataCommand.ExecuteReader();
  36.  
  37. while (dataReader.Read())
  38. {
  39. lbTeilnehmerliste.Items.Add(dataReader.GetString(0));
  40. }
  41. connection.Close();
  42. }
  43. }
  44. catch (Exception)
  45. {
  46.  
  47. throw;
  48. }
  49. }
  50. private void LabelText(string connectionString)
  51. {
  52. try
  53. {
  54. using (OleDbConnection connection = new OleDbConnection(connectionString))
  55. {
  56. connection.Open();
  57. OleDbCommand dataCommand = connection.CreateCommand();
  58. dataCommand.Connection = connection;
  59. dataCommand.CommandText = "Select count(*) from Teilnehmer;";
  60.  
  61. OleDbDataReader dataReader = dataCommand.ExecuteReader();
  62. dataReader.Read();
  63. label1.Text = string.Format("Es sind {0} Teilnehmer gemeldet:", dataReader.GetValue(0).ToString());
  64. connection.Close();
  65. }
  66. }
  67. catch (Exception)
  68. {
  69.  
  70. throw;
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement