Link to home
Start Free TrialLog in
Avatar of sunny-j
sunny-j

asked on

Parameter asp.net question

Greetings Experts,

I need some guidance/direction as unable to get my head around this issue.

I found a way to display queries against our database within basic webmatrix pages. Now I want to experiment with allowing access to users to view own records. I have set up the membership and authentication login and all works as expected. This is linked to a basic database with just userid and email in user profile (database1).

I am hoping to retrieve the main tables from a second remote database (database2 - added to project as connection)


My question is how do I enable a user to view own records.

var db = Database.Open ("Database2");
    var SQLquery = "SELECT [WorkerId],[Email1] FROM [Table1] where WorkerId=@0";
 
 
if (!WebSecurity.IsAuthenticated) {
  Response.Redirect("~/Account/Login?returnUrl="
    + Request.Url.LocalPath);
  }

What I want to be able to write is as follows.

from the login information, ascertain userid and email (username) from database1,
cross check this email with Email1 from database 2 (unless there is another way to match users ) and if correct, display table from database2 to user.

Any help greatly appreciated.

Kind regards. SJ
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Hi,

If I understand correctly, you want to present user with login screen.

User enters userid and email and then you compare that with userid and email from database1.

What would be your reason for comparing email and userid from database1 to same information from database2?
Avatar of sunny-j
sunny-j

ASKER

Hi Sammy,
I want to retrieve information from database 2 so I presume that I would need to link the databases. But if you feel that is not necessary and it's still possible to show user information according to profile, then pls guide on how I approach this issue. Kind regards SJ
Ok, I see

So, the link between database1 and database2 is email?

If it was me, an auto generated id from database1 and inserted into database2 as foreign key to database1 would have been a preferred approach.

However, if you are confident that you would not run into email duplication then I would try something like this:

select d1.userid, d1.email, d2.field1, d2.field2, d2.fieldn from database1 d1 inner join database2 d2 on d1.email = d2.email1 where d1.email = emailparam

Is that what you are after or did I miss something?
Avatar of sunny-j

ASKER

Thank you Sammy, i think that will work and will try later. Pls can you kindly list the next steps required to display the user data based on login. Essentially I need some basic outline on the code needed to link a login with data, so when testing each login, I am able to retrieve the correct data. Thanks again, SJ
ASKER CERTIFIED SOLUTION
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunny-j

ASKER

Perfect Sammy, I appreciate your swift answer, I am using web matrix and i take it this approach will work in razor c# code. Essentially I need to try and match the session email and password with websecurity.   I am away tonight and will try this out when home tomorrow, thank you again, have a good day.
The code is in vb but you can easily convert it to c# flavor.
Avatar of sunny-j

ASKER

Dear Sammy, thanks again for all your help. In the end I wasn't able to get my head around it, especially trying to do an inner join on the second database within WebMatrix. I am going to try again on another question, maybe approach it differently.  I hope you may be able to help again. Kind regards. SJ