Reputation: 33
I have this project I am working on for an assignment, and I have a question working with ASP.NET and SQL Server. I have a login page that kinda works, but there are two tables that I need to get data from - users (subscribers
) and admin page but am unsure how to access both of them as I can only access one.
public void login(Object src,EventArgs e)
{
get_connection();
try
{
connection.Open();
command = new SqlCommand("SELECT * FROM subscribers WHERE Email = @Email AND Password = @Password", connection);
command.Parameters.AddWithValue("@Email", loginName.Text);
command.Parameters.AddWithValue("@Password", loginPass.Text);
//command = new SqlCommand("SELECT * FROM admin WHERE Email =@Email and Password = @Password", connection);
//command.Parameters.AddWithValue("@Email", loginName.Text);
//command.Parameters.AddWithValue("@Password", loginPass.Text);
reader = command.ExecuteReader();
I commented out the admin part because when I include it, only admin username and password is accepted and not subscribers. What would I need to do to fix this?
Upvotes: 0
Views: 124
Reputation: 2048
The "admin part" causes you to only get records from the admin table because you're destroying and recreating your SqlCommand object. You'll need to create a new command in a different variable and read from it separately. There are ways to get multiple recordsets in the same call but I don't recommend it in this case.
That out of the way... Normally I'd expect to see a single users table with permissions/roles granted elsewhere. Consider something like the out of the box ASP.NET membership provider to take care of these implementation details for you:
Upvotes: 1