i’m creating a login page for my web application in ASP.net & C#, using visual studio 2010.
My login page is empty, just has 2 text boxes for username and password and a submit button, with some required field validations on each control.
I’m using SQL Server 2012 and have 3 tables in there, Student, Staff, and Admins, each one has two columns for Username and password.
What i would like to do is when the user presses the submit button, it checks the student table for the username and its password, if its not there, it checks the staff, then the admins. If its not in any of them, it gives an error that the login failed.
I put an SQLdatasource on the page that pulls the username and password from the student table where they are equal to the textboxes text.
Do i need to add 3 sqldatasources to page for each table? and what do i have to do after that?
Well – I agree that you should perhaps refactor, but to answer your question:
Since you are only reading data you can use a union over your three tables in your select.
Example from http://msdn.microsoft.com/en-us/library/ms180026.aspx
and modify the
SelectCommandin your datasource.