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 System.Data.OleDb;
- namespace AccessLoginApp
- {
- public partial class Form1 : Form
- {
- private OleDbConnection connection = new OleDbConnection();
- public Form1()
- {
- InitializeComponent();
- connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\12345\Desktop\laba\database7.accdb;
- Persist Security Info=False;";
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- try
- {
- connection.Open();
- checkConnection.Text = "Connection Successful";
- connection.Close();
- }
- catch(Exception ex)
- {
- MessageBox.Show("Error " + ex);
- }
- }
- private void bin_Login_Click(object sender, EventArgs e)
- {
- connection.Open();
- OleDbCommand command = new OleDbCommand();
- command.Connection = connection;
- command.CommandText = "select * from Tablet where Username= '"+txt_Username.Text+"' and Password= '"+txt_Password.Text+"'";
- OleDbDataReader reader = command.ExecuteReader();
- int count = 0;
- while (reader.Read())
- {
- count = count + 1;
- //count++
- }
- if(count == 1)
- {
- MessageBox.Show("Username and password is correct");
- }
- if (count > 1)
- {
- MessageBox.Show("Dublicate Username and password");
- }
- else
- {
- MessageBox.Show("Username and password is not correct");
- }
- connection.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement