Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 FloristPOS
- {
- public partial class Form1 : Form
- {
- MySqlConnection con = new MySqlConnection(@"Server=localhost;Database=florist;Uid=root;Pwd=1234;");
- int i;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- i = 0;
- //Open Database Connection
- con.Open();
- //Create mysql command
- MySqlCommand cmd = con.CreateCommand();
- cmd.CommandType = CommandType.Text;
- //Query to select all the username and password from the database which corresponds to textboxes
- cmd.CommandText = "select * from users where Username='" + txtUser.Text + "' and Password='" + txtPass.Text + "'";
- //Execute the query
- cmd.ExecuteNonQuery();
- DataTable dt = new DataTable();
- MySqlDataAdapter da = new MySqlDataAdapter(cmd);
- da.Fill(dt);
- i = Convert.ToInt32(dt.Rows.Count.ToString());
- //Messagebox if incorrect credentials
- if (i == 0)
- {
- MessageBox.Show("Invalid username or password", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
- txtPass.Text = "";
- txtUser.Text = "";
- }
- else
- {
- this.Hide();
- Form2 fm = new Form2();
- fm.Show();
- }
- con.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement