Guest User

Login

a guest
Apr 20th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. SqlCeConnection con = new SqlCeConnection("Data Source=\"" + System.IO.Path.Combine(Application.StartupPath, "Info.sdf") + "\"");
  2.         public login()
  3.         {
  4.             InitializeComponent();
  5.      
  6.         }
  7.  
  8.         bool status = true;
  9.         private void login_btn_Click(object sender, EventArgs e)
  10.         {
  11.             try
  12.             {
  13.                 if(status == true)
  14.                     con.Open();
  15.                 status = false;
  16.  
  17.                 if (username.Text == "" || password.Text == "")
  18.                 {
  19.                     MessageBox.Show("Enter Username and Password");
  20.                     return;
  21.                 }
  22.                
  23.                 //string query = ;
  24.                
  25.                 SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM 'user' WHERE username=@username AND password=@pass", con);
  26.                 cmd.Parameters.AddWithValue("@username", username.Text);
  27.                 cmd.Parameters.AddWithValue("@pass", password.Text);
  28.  
  29.                 SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
  30.                 DataTable dt = new DataTable();
  31.                 da.Fill(dt);
  32.                 dataGridView1.DataSource = dt;
  33.  
  34.                 //MessageBox.Show(dt.Rows.Count.ToString());
  35.  
  36.                 if (dt.Rows.Count > 0)
  37.                 {
  38.                     MessageBox.Show("Ok");
  39.                 }
  40.                 else
  41.                     MessageBox.Show("Invalid");
  42.             }
  43.             catch (SqlCeException ex)
  44.             {
  45.  
  46.                 MessageBox.Show(ex.Message);
  47.             }
  48.            
  49.  
  50.         }
Add Comment
Please, Sign In to add comment