Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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 WindowsFormsApp1
  14. {
  15. public partial class Form1 : Form
  16. {
  17. MySqlConnection con;
  18. MySqlCommand cmd;
  19. MySqlDataReader dr;
  20.  
  21.  
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. con = new MySqlConnection("Server=localhost;Database=Session1;user=root;Pwd='';SslMode=none");
  26. }
  27.  
  28. private void Form1_Load(object sender, EventArgs e)
  29. {
  30.  
  31. }
  32.  
  33. private void btnLogin_Click(object sender, EventArgs e)
  34. {
  35. string user = username.Text;
  36. string pass = password.Text;
  37. cmd = new MySqlCommand();
  38. con.Open();
  39. cmd.Connection = con;
  40. cmd.CommandText = "SELECT * FROM users where FirstName='" + username.Text + "' AND Password='" + password.Text + "'";
  41. dr = cmd.ExecuteReader();
  42. if (dr.Read())
  43. {
  44. MessageBox.Show("Login sucess ");
  45. var form2 = new Form2();
  46. form2.Show();
  47. }
  48. else
  49. {
  50. MessageBox.Show("Invalid Login please check username and password");
  51. }
  52. con.Close();
  53.  
  54.  
  55.  
  56. }
  57.  
  58. private void btnExit_Click(object sender, EventArgs e)
  59. {
  60. Application.Exit();
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement