Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace test_zapytan
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- //database stuff
- private const String SERVER = "212.237.20.10";
- private const String DATABASE = "inzynierka";
- private const String UID = "patryk";
- private const String PASSWORD = "haslo12345";
- private static MySqlConnection dbConn;
- public static void InitializeDB()
- {
- MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
- builder.Server = SERVER;
- builder.UserID = UID;
- builder.Password = PASSWORD;
- builder.Database = DATABASE;
- String connString = builder.ToString();
- builder = null;
- Console.WriteLine(connString);
- dbConn = new MySqlConnection(connString);
- Application.ApplicationExit += (sender, args) => {
- if (dbConn != null)
- {
- dbConn.Dispose();
- dbConn = null;
- }
- };
- }
- private void button1_Click(object sender, EventArgs e)
- {
- InitializeDB();
- int id=4328;
- String rfid = "1792619273";
- String query = string.Format("SELECT id FROM dostep WHERE rfidnumber LIKE '{0}'", rfid);
- MySqlCommand cmd = new MySqlCommand(query, dbConn);
- dbConn.Open();
- MySqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- id = (int)reader["id"];
- }
- reader.Close();
- dbConn.Close();
- textBox1.Text = id.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement