Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alpha_falcon11329449378746
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace Testing1
- {
- public partial class Form_Login : Form
- {
- MySqlConnection conn;
- MySqlDataReader mdr;
- //mdr = cmd.ExecuteReader();
- int i;
- public Form_Login()
- {
- InitializeComponent();
- //MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection);
- }
- private void Label1_Click(object sender, EventArgs e)
- {
- }
- private void Button1_Click(object sender, EventArgs e)
- {
- i = 0;
- try
- {
- string MySQLConnectionString = "datasource=127.0.0.1;port=3306;username=root;password=;database=testing";
- MySqlConnection databaseConnection = new MySqlConnection(MySQLConnectionString);
- conn = new MySql.Data.MySqlClient.MySqlConnection();
- conn.ConnectionString = MySQLConnectionString;
- conn.Open();
- MySqlCommand cmd = new MySqlCommand("SELECT * FROM users where userName='" + textBox1.Text + "'and password='" + textBox2.Text + "'", databaseConnection);
- MySqlCommand cmdRead = new MySqlCommand("SELECT firstName FROM users where userName='" + textBox1.Text + "'", databaseConnection);
- if (conn.State != ConnectionState.Open)
- {
- cmd.ExecuteNonQuery();
- mdr = cmd.ExecuteReader();
- }
- DataTable dt = new DataTable();
- MySqlDataAdapter da = new MySqlDataAdapter(cmd);
- da.Fill(dt);
- i = Convert.ToInt32(dt.Rows.Count.ToString());
- if(i == 0)
- {
- MessageBox.Show("Login Failure");
- } else
- {
- MessageBox.Show("Login Success");
- if (mdr.Read())
- {
- catcher.Text = mdr.GetString("firstName").ToString();
- }
- else MessageBox.Show("Shit");
- }
- }
- catch (MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void Label4_Click(object sender, EventArgs e)
- {
- var form1 = new Form();
- var form2 = new Form2();
- form1.Hide();
- form2.Show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement