Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace test_zapytan
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21.  
  22. //database stuff
  23. private const String SERVER = "212.237.20.10";
  24. private const String DATABASE = "inzynierka";
  25. private const String UID = "patryk";
  26. private const String PASSWORD = "haslo12345";
  27. private static MySqlConnection dbConn;
  28.  
  29.  
  30.  
  31. public static void InitializeDB()
  32. {
  33. MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
  34. builder.Server = SERVER;
  35. builder.UserID = UID;
  36. builder.Password = PASSWORD;
  37. builder.Database = DATABASE;
  38.  
  39. String connString = builder.ToString();
  40.  
  41. builder = null;
  42.  
  43. Console.WriteLine(connString);
  44.  
  45. dbConn = new MySqlConnection(connString);
  46.  
  47. Application.ApplicationExit += (sender, args) => {
  48. if (dbConn != null)
  49. {
  50. dbConn.Dispose();
  51. dbConn = null;
  52. }
  53. };
  54. }
  55.  
  56. private void button1_Click(object sender, EventArgs e)
  57. {
  58. InitializeDB();
  59. int id=4328;
  60. String rfid = "1792619273";
  61. String query = string.Format("SELECT id FROM dostep WHERE rfidnumber LIKE '{0}'", rfid);
  62.  
  63. MySqlCommand cmd = new MySqlCommand(query, dbConn);
  64.  
  65. dbConn.Open();
  66.  
  67. MySqlDataReader reader = cmd.ExecuteReader();
  68.  
  69. while (reader.Read())
  70. {
  71. id = (int)reader["id"];
  72.  
  73.  
  74. }
  75.  
  76. reader.Close();
  77.  
  78. dbConn.Close();
  79.  
  80. textBox1.Text = id.ToString();
  81.  
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement