Skip to content
Advertisement

Retrieving credentials from multiple tables in ASP

I want to have a login page that’ll take the email and password from 2 different tables in the same database. I have a student_regis and a Uni_regis table and these both cannot be combined in the same table since during registration there are different not null values for both the tables.

I’ve tried using UNION but it doesn’t work.

Here’s my code:

protected void Button1_Click(object sender, EventArgs e)
{
    String query = select count(*) 
                    from student_regis 
                    where email='" + mail.Text + "' and password='" + password.Text + "' 
                    union 
                    select count(*) 
                    from student_regis 
                    where email = '" + mail.Text + "' and password = '" + password.Text + "';

    SqlCommand cmd = new SqlCommand(query, scon);

    String output = cmd.ExecuteScalar().ToString();

    if (output == "1")
    {
        Response.Redirect("~/Home_page.aspx");
    }
    else
    {
        Response.Write("Username or password was wrong");
    }
} 

Advertisement

Answer

You can try, make two queries, one for student and another to ‘uni’, and make one

else if (output2 == "1")
{
    Response.Redirect("~/Home_page.aspx");
}
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement