Hi All

I am currently creating a website usng asp.net and C#. I have written code to make a simple user login. This just checks my database to match an inputed user name and password and if it returns any rows redirects to the home page. Ive now extended my sql query to look for the access level of a user so i can then redirect the user different pages. However now ive done this i am getting the following error. No value given for one or more required parameters. I am sure its the sql thats the problem but am pretty new to connecting to database and struggling to find the answer. Any help would be greatly appreciated.

Heres the method i created to do the above..

protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection connection = new OleDbConnection(connectionString);

connection.Open();

OleDbCommand command = new OleDbCommand("SELECT [User login].UserName,[User login].Password, [User login].Access FROM [User login] where [User login].UserName ='" + TextBox2.Text + "' and [User login].Password ='" + TextBox1.Text + "'", connection);

OleDbDataReader reader = command.ExecuteReader();


        if (reader.HasRows)
        {

            while (reader.Read())
            {
                string AccessLevel = (string)reader["Access"];

                if (AccessLevel == "Master")
                {
                    Response.Redirect("Home.aspx");
                }
                if (AccessLevel == "Admin")
                {
                    Response.Redirect("Home.aspx");
                }
                if (AccessLevel == "User")
                {
                    Response.Redirect("Home.aspx");
                }
            }

        }
        else
        {
            Label1.Text = "Error..... Please enter valid user name and password";
        }
        connection.Close();
    }

Many thanks

In advance

If you're using a dataset try this...

After your SELECT statement put whatever youre dataset name is .EnforceConstraints = false;

for example:

testDataSet.EnforceConstraints = false;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.