Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- private OleDbConnection connection = new OleDbConnection();
- public Form1()
- {
- InitializeComponent();
- connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersBahoDesktopUAVUAVbinDebuguav.accdb;
- Persist Security Info=False;";
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- try
- {
- connection.Open();
- checkConnection.Text = "Connection Successful";
- connection.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error " + ex);
- }
- }
- private void btnLogin_Click(object sender, EventArgs e)
- {
- connection.Open();
- OleDbCommand command = new OleDbCommand();
- command.Connection = connection;
- command.CommandText = "select * from Login where UserName='"+ txtUserName.Text+ "' and Password='"+ txtPassword.Text + "'";
- OleDbDataReader reader = command.ExecuteReader();
- int count = 0;
- while (reader.Read())
- {
- count = count + 1;
- }
- if(count==1)
- {
- MessageBox.Show("Username and Password is correct");
- connection.Close();
- connection.Dispose();
- this.Hide();
- Form2 f2= new Form2();
- f2.ShowDialog();
- }
- else if (count > 1)
- {
- MessageBox.Show("Duplicate Username and Password");
- }
- else
- {
- MessageBox.Show("Username and Password is not correct");
- }
- connection.Close();
- }
- }
- public partial class Form1 : Form
- {
- private string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersBahoDesktopUAVUAVbinDebuguav.accdb;Persist Security Info=False;";
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- try
- {
- using (var connection = new OleDbConnection(connectionString))
- {
- connection.Open();
- checkConnection.Text = "Connection Successful";
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error " + ex);
- }
- }
- private void btnLogin_Click(object sender, EventArgs e)
- {
- var numberOfLogins = 0;
- using (var connection = new OleDbConnection(connectionString))
- {
- connection.Open();
- var commandText = "select * from Login where UserName=@UserName and Password=@Password";
- using (var command = new OleDbCommand(commandText, connection))
- {
- command.Parameters.AddWithValue("UserName", txtUserName.Text);
- command.Parameters.AddWithValue("Password", txtPassword.Text);
- using (var reader = command.ExecuteReader())
- {
- while (reader.Read())
- {
- numberOfLogins = numberOfLogins + 1;
- }
- }
- }
- }
- if (count == 1)
- {
- MessageBox.Show("Username and Password is correct");
- this.Hide();
- Form2 f2 = new Form2();
- f2.ShowDialog();
- }
- else if (count > 1)
- {
- MessageBox.Show("Duplicate Username and Password");
- }
- else
- {
- MessageBox.Show("Username and Password is not correct");
- }
- }
- }
Add Comment
Please, Sign In to add comment