Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. string connStr ="server=10.241.0.1;user=sqlhazi;database=sqlbeadando;port=3306;password=ntRaEXZ0qbjm";
  2. MySqlConnection conn = new MySqlConnection(connStr);
  3. var result= new List<string>();
  4. try{
  5. Console.WriteLine("Connecting to MySQL:");
  6. conn.Open();
  7. //itt használom az adatbázis lekérdezést
  8. string sql = "select question from Question where exam_id = 0 order by rand() limit 6;"; //sqles parancsot ide
  9. MySqlCommand cmd = new MySqlCommand(sql, conn);
  10. MySqlDataReader reader = cmd.ExecuteReader();
  11. while (reader.Read())
  12. {
  13. //Console.WriteLine((string)reader["question"]);
  14. result.Add((string)reader["question"]);
  15.  
  16. }
  17. reader.Close();
  18. }catch (Exception ex){
  19. Console.WriteLine(ex.ToString());
  20. }
  21. conn.Close();
  22. Console.WriteLine("Done...");
  23. return result;
  24. }
  25.  
  26. // 1 tárgy
  27. public List<string> get2(){
  28. string connStr ="server=10.241.0.1;user=sqlhazi;database=sqlbeadando;port=3306;password=ntRaEXZ0qbjm";
  29. MySqlConnection conn = new MySqlConnection(connStr);
  30. var result= new List<string>();
  31. try{
  32. Console.WriteLine("Connecting to MySQL:");
  33. conn.Open();
  34. //itt használom az adatbázis lekérdezést
  35. string sql = "select question from Question where exam_id = 1 order by rand() limit 6;"; //sqles parancsot ide
  36. MySqlCommand cmd = new MySqlCommand(sql, conn);
  37. MySqlDataReader reader = cmd.ExecuteReader();
  38. while (reader.Read())
  39. {
  40. //Console.WriteLine((string)reader["question"]);
  41. result.Add((string)reader["question"]);
  42.  
  43. }
  44. reader.Close();
  45. }catch (Exception ex){
  46. Console.WriteLine(ex.ToString());
  47. }
  48. conn.Close();
  49. Console.WriteLine("Done...");
  50. return result;
  51. }
  52.  
  53. //targy 3
  54. public List<string> get3(){
  55. string connStr ="server=10.241.0.1;user=sqlhazi;database=sqlbeadando;port=3306;password=ntRaEXZ0qbjm";
  56. MySqlConnection conn = new MySqlConnection(connStr);
  57. var result= new List<string>();
  58. try{
  59. Console.WriteLine("Connecting to MySQL:");
  60. conn.Open();
  61. //itt használom az adatbázis lekérdezést
  62. string sql = "select question from Question where exam_id = 2 order by rand() limit 6;"; //sqles parancsot ide
  63. MySqlCommand cmd = new MySqlCommand(sql, conn);
  64. MySqlDataReader reader = cmd.ExecuteReader();
  65. while (reader.Read())
  66. {
  67. //Console.WriteLine((string)reader["question"]);
  68. result.Add((string)reader["question"]);
  69.  
  70. }
  71. reader.Close();
  72. }catch (Exception ex){
  73. Console.WriteLine(ex.ToString());
  74. }
  75. conn.Close();
  76. Console.WriteLine("Done...");
  77. return result;
  78. }
  79. //targy 4
  80.  
  81. public List<string> get4(){
  82. string connStr ="server=10.241.0.1;user=sqlhazi;database=sqlbeadando;port=3306;password=ntRaEXZ0qbjm";
  83. MySqlConnection conn = new MySqlConnection(connStr);
  84. var result= new List<string>();
  85. try{
  86. Console.WriteLine("Connecting to MySQL:");
  87. conn.Open();
  88. //itt használom az adatbázis lekérdezést
  89. string sql = "select question from Question where exam_id = 3 order by rand() limit 6;"; //sqles parancsot ide
  90. MySqlCommand cmd = new MySqlCommand(sql, conn);
  91. MySqlDataReader reader = cmd.ExecuteReader();
  92. while (reader.Read())
  93. {
  94. //Console.WriteLine((string)reader["question"]);
  95. result.Add((string)reader["question"]);
  96.  
  97. }
  98. reader.Close();
  99. }catch (Exception ex){
  100. Console.WriteLine(ex.ToString());
  101. }
  102. conn.Close();
  103. Console.WriteLine("Done...");
  104. return result;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement