Advertisement
Biciklee

Untitled

Nov 4th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 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;
  11. using MySql.Data.MySqlClient;
  12.  
  13. namespace WindowsFormsApplication1
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         MySqlConnection connection;
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.             ConnectToDatabase();
  23.         }
  24.  
  25.         private void ConnectToDatabase()
  26.         {
  27.             try
  28.             {
  29.                 MySqlConnectionStringBuilder conn_string = new MySqlConnectionStringBuilder();
  30.                 conn_string.Server = "127.0.0.1";
  31.                 conn_string.UserID = "root";
  32.                 conn_string.Port = 3307;
  33.                 conn_string.Password = "";
  34.                 conn_string.Database = "test";
  35.  
  36.                 connection = new MySqlConnection(conn_string.ToString());
  37.                 connection.Open();
  38.             }
  39.             catch (Exception ex)
  40.             {
  41.                 MessageBox.Show("Hiba:" + ex.Message);
  42.             }
  43.         }
  44.  
  45.         private void loginButton_Click(object sender, EventArgs e)
  46.         {
  47.             try
  48.             {
  49.                 MySqlCommand cmd = connection.CreateCommand();
  50.                 cmd.CommandText = "SELECT * FROM users where user='" + userText.Text + "' AND pw='" + passText.Text + "'";
  51.                 using (MySqlDataReader reader = cmd.ExecuteReader())
  52.                 {
  53.                     if (reader.Read())
  54.                     {
  55.                         MessageBox.Show("Sikeres belépés");
  56.                     }
  57.                     else
  58.                     {
  59.                         MessageBox.Show("Hibás belépési adatok");
  60.                     }
  61.                 }
  62.  
  63.                
  64.             }
  65.             catch (Exception ex)
  66.             {
  67.                 MessageBox.Show("Hiba:" + ex.Message);
  68.             }
  69.  
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement