I have copied the exact code from a tutorial and all the connection build up thing is working and my Sql select statement is also working just that the Reader command is not functioning the Reader is malfunctioning and does not incrementing the Count value.
Heres 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.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string myConnection = "datasource= localhost;port=3306;username=root;password=2905";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand Selectcommand = new MySqlCommand("select *from mydb.supervisors where username='" + this.text1_txt + "' and password = '" + this.text2_txt + "';", myConn);
myConn.Open();
MySqlDataReader myReader;
myReader = Selectcommand.ExecuteReader();
int count = 0;
while (myReader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Yayyyy");
}
else if (count > 1)
{
MessageBox.Show("Duplicate Parameters - Accesss Denied");
}
else if (count == 0)
{
MessageBox.Show("UserName, Password Dont Match with Hostel");
myConn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}