Advertisement
Guest User

a guest
May 14th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 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.  
  13.  
  14. namespace Testing1
  15. {
  16.     public partial class Form_Login : Form
  17.     {
  18.         MySqlConnection conn;
  19.         MySqlDataReader mdr;
  20.         //mdr = cmd.ExecuteReader();
  21.         int i;
  22.        
  23.  
  24.         public Form_Login()
  25.         {
  26.             InitializeComponent();
  27.            
  28.  
  29.             //MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);
  30.         }
  31.  
  32.         private void Label1_Click(object sender, EventArgs e)
  33.         {
  34.  
  35.         }
  36.  
  37.         private void Button1_Click(object sender, EventArgs e)
  38.         {
  39.             i = 0;
  40.             try
  41.             {
  42.                 string MySQLConnectionString = "datasource=127.0.0.1;port=3306;username=root;password=;database=testing";
  43.  
  44.                 MySqlConnection databaseConnection = new MySqlConnection(MySQLConnectionString);
  45.  
  46.                 conn = new MySql.Data.MySqlClient.MySqlConnection();
  47.                 conn.ConnectionString = MySQLConnectionString;
  48.                 conn.Open();
  49.  
  50.                 MySqlCommand cmd = new MySqlCommand("SELECT * FROM users where userName='" + textBox1.Text + "'and password='" + textBox2.Text + "'", databaseConnection);
  51.                 MySqlCommand cmdRead = new MySqlCommand("SELECT firstName FROM users where userName='" + textBox1.Text + "'", databaseConnection);
  52.                 if (conn.State != ConnectionState.Open)
  53.                 {
  54.                     cmd.ExecuteNonQuery();
  55.                     mdr = cmd.ExecuteReader();
  56.                 }
  57.                 DataTable dt = new DataTable();
  58.                 MySqlDataAdapter da = new MySqlDataAdapter(cmd);
  59.                 da.Fill(dt);
  60.                 i = Convert.ToInt32(dt.Rows.Count.ToString());
  61.  
  62.                 if(i == 0)
  63.                 {
  64.                     MessageBox.Show("Login Failure");
  65.                 } else
  66.                 {
  67.                     MessageBox.Show("Login Success");
  68.                     if (mdr.Read())
  69.                     {
  70.                         catcher.Text = mdr.GetString("firstName").ToString();
  71.                     }
  72.                     else MessageBox.Show("Shit");
  73.                    
  74.                 }
  75.             }
  76.             catch (MySqlException ex)
  77.             {
  78.                 MessageBox.Show(ex.Message);
  79.             }
  80.  
  81.            
  82.         }
  83.  
  84.         private void Label4_Click(object sender, EventArgs e)
  85.         {
  86.             var form1 = new Form();
  87.             var form2 = new Form2();
  88.             form1.Hide();
  89.             form2.Show();
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement