Hello I am new to csharp and am having some trouble with a projec that I am working on. I have a database(access) and am using a window form for a login page. The login is supposed to check a couple conditions and then return an int from the database which says which accesslevel that login has. Something is wrong with my code I am having trouble with making the return value an int and am just lost. Any help would be appreciated my code is below.

private void Submitbutton_Click(object sender, EventArgs e)
        {
            OleDbConnection objconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c://documents and settings/davidsinclair/My Documents/Visual Studio 2005/Projects/PINS/PINS/pinsdb.mdb");
            OleDbCommand cmdLogin = new OleDbCommand("select EmployeeAccessLevel from OSicher where (EmployeeName = 'warehouse' AND EmployeePassword = 'house') OR (EmployeeName = 'inventory' AND EmployeePassword = 'staff')", objconn);
            try
            {
                objconn.Open();
                OleDbDataReader radLogin = cmdLogin.ExecuteReader();
                while (radLogin.Read())
                {
                    int result = (int)radLogin(EmployeeAccessLevel);
                    if (result = "1")
                    {
                        frmManagerHome frm = new frmManagerHome();
                        frm.Show();
                    }
                }
                radLogin.Close();
                objconn.Close();
            }
            catch(OleDbException er)
            {
                Console.WriteLine("Error: {0}", er.Errors[0].Message);
            }
        }

first, you are setting result to be an int

int result = (int)radLogin(EmployeeAccessLevel);

and then comparing it to a string

if (result = "1")

. second, you are trying to use = to compare instead of ==.

if (result = "1")

.

change the second line to

if (result == 1)

Thanks for the help, I got that worked out and now when I run it I get Exception errors.

Thanks for the help, I got that worked out and now when I run it I get Exception errors.

What exception errors are you getting, exactly?

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