Form1.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace Kurs09
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. pass.PasswordChar = '*';
  19. }
  20. private void buttonLogin_Click(object sender, EventArgs e)
  21. {
  22. string loginUser = login.Text;
  23. String passUser = pass.Text;
  24. DB db = new DB();
  25. DataTable table = new DataTable();
  26. MySqlDataAdapter adapter = new MySqlDataAdapter();
  27. MySqlCommand command = new MySqlCommand("SELECT * FROM users WHERE login = @uL AND pass = @uP", db.GetConnection());
  28. command.Parameters.Add("@uL", MySqlDbType.VarChar).Value = loginUser;
  29. command.Parameters.Add("@uP", MySqlDbType.VarChar).Value = passUser;
  30. adapter.SelectCommand = command;
  31. adapter.Fill(table);
  32. if (table.Rows.Count > 0)
  33. MessageBox.Show("Yes");
  34. else
  35. MessageBox.Show("No");
  36. }
  37. }
  38. }