Hi
I am using C# 2008 with Access 2007. I am using MDI on MDI a added a menu now that Menu have a Login MenuItem which is enable and other menu items are disabled at form load. Now I am try to implement this if login is successful then other menu items will be enabled automatically. I tried lots of technique but I can't able to access Menu Items from Login Form. What I tried here is the code -

namespace EzBuddy
{
    public partial class UserLoginForm : Form
    {
        //public NewUser nuser1;
        private OleDbDataReader aReader;
        private OleDbCommand aCommand;
        private OleDbConnection aConnection;
        public int login_flag = 0;

        public UserLoginForm()
        {
            InitializeComponent();
        }
        public void menuEnable()
        {
           
        }
        public void login_code()
        {
            int x = LoginBox.TextLength;
            if (x < 5 || LoginBox.Text.Equals(""))
            {
                MessageBox.Show("ID is of minimum 5 digits as your Permanent Emplolee code or 9 digits as your Temporary Employee code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LoginBox.Text = "";
                PasswordBox.Text = "";
                LoginBox.Focus();
            }
            try
            {
                database_Connection();
                aReader = aCommand.ExecuteReader();
               
                while (aReader.Read())
                {
                    if (aReader.GetString(0).Equals(LoginBox.Text) && aReader.GetString(1).Equals(PasswordBox.Text))
                    {
                         login_flag = 1;
                        break;
                    }
                    else
                    {
                        login_flag = 0;
                    }
                }
                if (login_flag == 1)
                {
                    [B]MDIParentForm.loginToolStripMenuItem1.Enabled = false;
                    MDIParentForm.newToolStripMenuItem3.Enabled = true;
                    MDIParentForm.editToolStripMenuItem3.Enabled = true;
                    MDIParentForm.deleteToolStripMenuItem3.Enabled = true;
                    MDIParentForm.
                    MDIParentForm.searchToolStripMenuItem1.Enabled = true;
                    MDIParentForm.reportsToolStripMenuItem1.Enabled = true;
                    MDIParentForm.utilitiesToolStripMenuItem.Enabled = true;[/B]
                    this.Dispose();
                }
                else
                {
                    LoginBox.Text = "";
                    PasswordBox.Text = "";
                    LoginBox.Focus();
                    loginMessage.Visible = true;
                    aReader.Close();
                    aConnection.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
            finally
            {
                aReader.Close();
                aConnection.Close();
            }
        }
        private void database_Connection()
        {
            try
            {
                aConnection.Open();
                Console.WriteLine("This is the returned data from Login table");
            }
            catch (OleDbException e)
            {
                Console.WriteLine("Error: {0}", e.Errors[0].Message);
            }
        }

        private void UserLoginForm_Load(object sender, EventArgs e)
        {
            aConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\KVSoftware\\KVStudent\\KV1StudentInformation.mdb");
            aCommand = new OleDbCommand("select * from Login", aConnection);
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {
            login_code();
        }

    }
}

Help me to solve this problem

You can take a shortcut...create 2menus and on the 1st menu put the log-in part,on the second menu put everything you need after successful log in.
If your log in is successful then hide the log-in menu and show the other menu,else keep showing the log in menu or something that your program demands.
considering you have manu1 and menu2 as your two menu-bars, the algorithm should be sumthing like dis:

If(condition for log-in = success)
{
hide menu1;
show menu2;
}
else
{
do as ur program needs
}

This article has been dead for over six months. Start a new discussion instead.