Hello folks, I'm a little stuck and any help would be appreciated. Basically what I'm trying to do is have the user enter a pin or password, connect to a database and check whether that password is in there, if it is the program will switch to a new form. The problem is i don't know how to compare the query result with what the user has entered into the textbox. Below is my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace FullProject
{
public partial class Form1 : Form
{
//Making form 1 static so i can get back to it from form 2 and making pin public so form 2 can use it
public static Form1 staticf = null;
public static string ent = null;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
//Only 6 characters can be entered in textbox
textBox1.MaxLength = 6;
}
private void enter_Click(object sender, EventArgs e)
{
//ent now equals the textbox
ent = textBox1.Text;
//Opening connection to database and execute query
MySqlConnection condatabase = new MySqlConnection("Data Source=localhost;" + "Persist Security Info=yes;" +
"UserID = root; PWD= ;");
MySqlCommand cmddatabase = new MySqlCommand("Use winc; Select pin From info Where pin = [box]" + ent);
condatabase.Open();
MySqlDataReader reader = cmddatabase.ExecuteReader();
string res = cmddatabase.ToString;
//If pin exists in database execute statement inside the if, ignore if condition as it was being used for testing
if (textBox1.Text == "1234")
{
staticf = this;
this.Hide();
textBox1.Text = null;
Form2 form2 = new Form2();
form2.Show();
}
else
{
//Display if pin isnt found in database
MessageBox.Show("Incorrect pin entered");
}
}
}
}