C# and MS Access

Discussion in 'C#' started by waal, May 9, 2012.

  1. waal

    waal New Member

    Joined:
    May 9, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. waal

    waal New Member

    Joined:
    May 9, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.Odbc;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;


    namespace eee1
    {
    public partial class Form1 : Form
    {


    public Form1()
    {
    InitializeComponent();
    }



    private void Button2_Click_1(object sender, EventArgs e)
    {
    this.Close();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    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();

    }

    }


    }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice