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 System.Data.OleDb;
namespace WindowsFormsAccessApp
{
public partial class Form1Password : Form
{
private OleDbConnection connection = new OleDbConnection(); // Global access with private connection to Form1
public Form1Password()
{
//Constructor of the the Form1 Class (loads one time)
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Access 2010\GlobalAddressLog2.accdb;
Persist Security Info=False;";
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
connection.Open();
Lbl_ConnectionValidation.Text = "Conncetion Successful";
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
// MessageBox.Show("LOST Connection");
}
}
private void bnt_Login_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand Command = new OleDbCommand();
Command.Connection = connection;
// Query
Command.CommandText = "SELECT * FROM GlobalAddressFile WHERE Username = '"+ txt_UserName.Text +"' and Password = '"+ txt_Password.Text +"' ";
OleDbDataReader Reader = Command.ExecuteReader(); // retruns a value (get values)
int count = 0; // declare interger variable = zero
while (Reader.Read()) // while True
{
count = count + 1;
}
if (count == 1)
{ MessageBox.Show("UserName and Password Correct");}
if (count > 1)
{ MessageBox.Show("Duplicate UserName and Password Correct"); }
if (count == 0)
{ MessageBox.Show("UserName and Password NOT Correct"); }
// Command.ExecuteNonQuery(); // retruns no value (insert, delete)
connection.Close();
}
private void txt_Password_TextChanged(object sender, EventArgs e)
{
}
// Command.ExecuteNonQuery(); // retruns no value (insert, delete)
connection.Close();
}
private void txt_Password_TextChanged(object sender, EventArgs e)
{
{ }
}
}
}