Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hello ,
i created database using MS access
contain Admin table{adminID, usertype, username, userpassword}
and staff table {staffID, password ....etc}, i want to create login form in C#
if the user is admin can login and can add staff's ID and put a password for them... also the staff can login by their ID and their own password.

please help i'm getting errors
C#
public partial class Form1 : Form
{
     
   private void Button2_Click_1(object sender, EventArgs e)
   {
      this.Close();
   }
   
   private void btnlogin_Click(object sender, EventArgs e)
   {
      OleDbConnection connection = new OleDbConnection(); 
      connection.ConnectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sss\Documents\Visual Studio 2010\Projects\eee1\eee1\EMP.accdb;adminId=admin;";
      connection.Open();

      OleDbCommand command = new OleDbCommand("SELECT * FROM Admin", connection); 
      OleDbDataReader reader = command.ExecuteReader(); 
      
      try
      {
         while (reader.Read()) 
         {
            txtuname.ToString();
            txtupass.ToString();

            if (txtuname.Text =="admin" &&txtupass.Text =="admin") 
            {
               this.Hide(); 
               new MainForm().Show();
               break; 
            }
            else
            {
               MessageBox.Show("UserName/Password doesnt exist"); 
               break; 
            }
         }
      }
      catch (Exception err) 
      {
         MessageBox.Show(err.Message); 
      }
      finally
      {
         connection.Close();
         command.Dispose();
         connection.Dispose();
      }
   }
}
Posted
Updated 9-May-12 9:06am
v3
Comments
OriginalGriff 9-May-12 15:05pm    
"please help i'm getting errors" is not a lot of use.
Where are you getting errors?
What errors are you getting?
Compilation? Run time? Database? Logic? Unknown?
Give us the information you have on your screen - we can't see it!
Use the "Improve question" widget to edit your question and provide better information.
waal1111 9-May-12 15:20pm    
when i run this code it shows Could not find installable ISAM.
fjdiewornncalwe 9-May-12 15:06pm    
You haven't provided enough information. You have simply dumped the code you have and want us to do your assignment. It doesn't work that way. You need to explain to us at what point you are having difficulty. From the code you have shown us, there isn't much help we can provide.
waal1111 9-May-12 15:20pm    
when i run this code it shows Could not find installable ISAM.

"Could not find installable ISAM"

In the case of
Provider=Microsoft.Jet.OLEDB.4.0
This normally means that you are running your program as a 64 bit application. There is no 64 bit version of the Jet OleDB drivers, so you get this message.

Try changing your project properties to generate a 32 bit application instead - if the problem goes away, then you need to decide if you are more wedded to Access or 64 bit applications!
 
Share this answer
 
Comments
waal1111 9-May-12 15:35pm    
thank u very much
Instead of defining a custom security mechanism, have you considered using the built-in user level security: About user-level security (MDB)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900