Loading...

If you have any confusion watch the following video:

 

Loading...

5 COMMENTS

  1. Hi

    I have copied the code , changed it to my settings , also watched the video and made the changes,
    I am connected to the database in visual studio – the form runs – when you attempt to put anything in the first box(user name) you get the incorrect username and password message:

    My Code is below

    using System;
    using System.Data;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;

    namespace stockcontroller
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button2_Click(object sender, EventArgs e)
    {
    Close();
    }

    private void button1_Click(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    MySqlConnection conn = new MySqlConnection(“server = localhost; user id = root; database = stockcontrol”);
    MySqlDataAdapter sda = new MySqlDataAdapter(“select count(*) from users where username = ‘” + txtuser.Text + “‘ and password = ‘” + txtpass.Text + “‘”, conn);
    DataTable dt = new DataTable();
    sda.Fill(dt);
    if (dt.Rows[0][0].ToString() == “1”)
    {
    MessageBox.Show(“username and password are matched”, “Connected”, MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
    {
    MessageBox.Show(“incorrect username and password”, “Failure”, MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

    }
    }
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.