Guest User

Untitled

a guest
Dec 19th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3. private OleDbConnection connection = new OleDbConnection();
  4. public Form1()
  5. {
  6. InitializeComponent();
  7. connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=‪‪C:UsersBahoDesktopUAVUAVbinDebuguav.accdb;
  8. Persist Security Info=False;";
  9. }
  10.  
  11. private void Form1_Load(object sender, EventArgs e)
  12. {
  13. try
  14. {
  15. connection.Open();
  16. checkConnection.Text = "Connection Successful";
  17. connection.Close();
  18. }
  19.  
  20. catch (Exception ex)
  21. {
  22. MessageBox.Show("Error " + ex);
  23. }
  24. }
  25.  
  26. private void btnLogin_Click(object sender, EventArgs e)
  27. {
  28. connection.Open();
  29. OleDbCommand command = new OleDbCommand();
  30. command.Connection = connection;
  31. command.CommandText = "select * from Login where UserName='"+ txtUserName.Text+ "' and Password='"+ txtPassword.Text + "'";
  32.  
  33. OleDbDataReader reader = command.ExecuteReader();
  34. int count = 0;
  35. while (reader.Read())
  36. {
  37. count = count + 1;
  38. }
  39. if(count==1)
  40. {
  41. MessageBox.Show("Username and Password is correct");
  42. connection.Close();
  43. connection.Dispose();
  44. this.Hide();
  45. Form2 f2= new Form2();
  46. f2.ShowDialog();
  47.  
  48. }
  49. else if (count > 1)
  50. {
  51. MessageBox.Show("Duplicate Username and Password");
  52. }
  53. else
  54. {
  55. MessageBox.Show("Username and Password is not correct");
  56. }
  57. connection.Close();
  58. }
  59. }
  60.  
  61. public partial class Form1 : Form
  62. {
  63. private string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=‪‪C:UsersBahoDesktopUAVUAVbinDebuguav.accdb;Persist Security Info=False;";
  64.  
  65. public Form1()
  66. {
  67. InitializeComponent();
  68. }
  69.  
  70. private void Form1_Load(object sender, EventArgs e)
  71. {
  72. try
  73. {
  74. using (var connection = new OleDbConnection(connectionString))
  75. {
  76. connection.Open();
  77. checkConnection.Text = "Connection Successful";
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. MessageBox.Show("Error " + ex);
  83. }
  84. }
  85.  
  86. private void btnLogin_Click(object sender, EventArgs e)
  87. {
  88. var numberOfLogins = 0;
  89. using (var connection = new OleDbConnection(connectionString))
  90. {
  91. connection.Open();
  92. var commandText = "select * from Login where UserName=@UserName and Password=@Password";
  93. using (var command = new OleDbCommand(commandText, connection))
  94. {
  95. command.Parameters.AddWithValue("UserName", txtUserName.Text);
  96. command.Parameters.AddWithValue("Password", txtPassword.Text);
  97.  
  98. using (var reader = command.ExecuteReader())
  99. {
  100. while (reader.Read())
  101. {
  102. numberOfLogins = numberOfLogins + 1;
  103. }
  104. }
  105. }
  106. }
  107.  
  108. if (count == 1)
  109. {
  110. MessageBox.Show("Username and Password is correct");
  111. this.Hide();
  112.  
  113. Form2 f2 = new Form2();
  114. f2.ShowDialog();
  115. }
  116. else if (count > 1)
  117. {
  118. MessageBox.Show("Duplicate Username and Password");
  119. }
  120. else
  121. {
  122. MessageBox.Show("Username and Password is not correct");
  123. }
  124. }
  125. }
Add Comment
Please, Sign In to add comment