Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SqlCeConnection con = new SqlCeConnection("Data Source=\"" + System.IO.Path.Combine(Application.StartupPath, "Info.sdf") + "\"");
- public login()
- {
- InitializeComponent();
- }
- bool status = true;
- private void login_btn_Click(object sender, EventArgs e)
- {
- try
- {
- if(status == true)
- con.Open();
- status = false;
- if (username.Text == "" || password.Text == "")
- {
- MessageBox.Show("Enter Username and Password");
- return;
- }
- //string query = ;
- SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM 'user' WHERE username=@username AND password=@pass", con);
- cmd.Parameters.AddWithValue("@username", username.Text);
- cmd.Parameters.AddWithValue("@pass", password.Text);
- SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
- DataTable dt = new DataTable();
- da.Fill(dt);
- dataGridView1.DataSource = dt;
- //MessageBox.Show(dt.Rows.Count.ToString());
- if (dt.Rows.Count > 0)
- {
- MessageBox.Show("Ok");
- }
- else
- MessageBox.Show("Invalid");
- }
- catch (SqlCeException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
Add Comment
Please, Sign In to add comment