Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.OleDb;
  11. namespace AccessLoginApp
  12. {
  13. public partial class Form1 : Form
  14. {
  15. private OleDbConnection connection = new OleDbConnection();
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\12345\Desktop\laba\database7.accdb;
  20. Persist Security Info=False;";
  21. }
  22.  
  23. private void Form1_Load(object sender, EventArgs e)
  24. {
  25. try
  26. {
  27. connection.Open();
  28. checkConnection.Text = "Connection Successful";
  29. connection.Close();
  30. }
  31. catch(Exception ex)
  32. {
  33. MessageBox.Show("Error " + ex);
  34. }
  35.  
  36.  
  37. }
  38.  
  39. private void bin_Login_Click(object sender, EventArgs e)
  40. {
  41. connection.Open();
  42. OleDbCommand command = new OleDbCommand();
  43. command.Connection = connection;
  44. command.CommandText = "select * from Tablet where Username= '"+txt_Username.Text+"' and Password= '"+txt_Password.Text+"'";
  45.  
  46. OleDbDataReader reader = command.ExecuteReader();
  47. int count = 0;
  48. while (reader.Read())
  49. {
  50. count = count + 1;
  51. //count++
  52.  
  53. }
  54. if(count == 1)
  55. {
  56. MessageBox.Show("Username and password is correct");
  57. }
  58. if (count > 1)
  59. {
  60. MessageBox.Show("Dublicate Username and password");
  61. }
  62. else
  63. {
  64. MessageBox.Show("Username and password is not correct");
  65. }
  66.  
  67.  
  68. connection.Close();
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement