Advertisement
Guest User

Untitled

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