Guest User

c#loginpage

a guest
May 10th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 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.  
  12. namespace WindowsFormsApplication21
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void button2_Click(object sender, EventArgs e)
  22. {
  23. Application.Exit();
  24. }
  25.  
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28.  
  29. if (textBox1.Text == "" || textBox2.Text == "")
  30. {
  31. label3.Text = "please plovide the field mensoined";
  32. label3.Visible = true;
  33. }
  34.  
  35.  
  36. else
  37. {
  38.  
  39. try
  40. {
  41. label3.Text = "wrong uername or password";
  42. OleDbConnection con=new OleDbConnection();
  43. con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\SurajNegi Data\data.accdb";
  44.  
  45.  
  46.  
  47.  
  48.  
  49. OleDbCommand cmd = new OleDbCommand("SELECT * from data where USERNAME=@user and PASSWORD=@pass",con);
  50. cmd.Parameters.AddWithValue("@user",textBox1.Text);
  51. cmd.Parameters.AddWithValue("@pass",textBox2.Text);
  52. con.Open();
  53. DataSet da = new DataSet();
  54. OleDbDataAdapter adt = new OleDbDataAdapter(cmd);
  55. adt.Fill(da);
  56. con.Close();
  57. int count = da.Tables[0].Rows.Count;
  58.  
  59. if (count > 0)
  60. {
  61. MessageBox.Show("WELCOME");
  62. }
  63. else
  64. {
  65. label3.Visible = true;
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. MessageBox.Show("cannot open {0}", ex.ToString());
  71. }
  72. }
  73.  
  74. }
  75. }
  76. }
Add Comment
Please, Sign In to add comment