Help with linking queries using c#

Greetings Experts,

Please could you guide on how I can display users records after login.


// Initialize general page variables
var authenticatedUser = "";
var authenticatedUserFirstName = "";
var authenticatedUserLastName = "";
var authenticatedUseremail ="";
if (WebSecurity.IsAuthenticated) {
authenticatedUser = WebSecurity.CurrentUserName;
var db = Database.Open("Db2");
var UserData = db.QuerySingle("Select a.Email1, a.FirstName, a.LastName from pro.Worker a inner join StarterSite.dbo.UserProfile b on b.Email = a.Email1 WHERE LOWER(Email) = LOWER(@0)", authenticatedUser);
authenticatedUserFirstName = UserData.FirstName;
authenticatedUserLastName = UserData.LastName;
//authenticatedUseremail = UserData.Email;


<!DOCTYPE html>

<html lang="en">
        <meta charset="utf-8" />
        @if (WebSecurity.IsAuthenticated) {
                                Hello, <a class="username" href="~/Account/PasswordReset" title="Change password"> @authenticatedUserFirstName  </a>!
                                <a href="~/Account/Logout">Logout</a>


Open in new window


 At this stage, I seem to be referencing the right user - now I would like to display tables and additional pages with results of queries related to their profile. Can you please point out how I do this. I am currently using the razor syntax in c# so appreciate sample code in this language as not proficient enough to convert.

 To give an example, this is what I would like to do..

Hello @user,
 Please find your profile information below
 Your Full Name @name
 Your email @email

 Please find current bookings below.. etc., ....

 Query from same database but different tables ( I can do the queries but struggling to see how they link up here so properly linking. )

 Thank you in anticipation of solutions. Kind regards. SJ
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You have this query:

Select a.Email1, a.FirstName, a.LastName from pro.Worker a
      inner join StarterSite.dbo.UserProfile b on b.Email = a.Email1
      WHERE LOWER(Email) = LOWER(@0)", authenticatedUser);

Are the profile properties to display pulled in that query?  If so, then my suggestion would be to pass in the UserData as the model to the view, and then you can reference the property like this:

sunny-jAuthor Commented:
Dear Bob, really appreciate your swift response. I think I am definitely overcomplicated what I am trying to do. Do you think it will help to try and do this without authentication in place just to get it working properly. I am having trouble getting my head around how to pass the parameter and display anything other than the authentication fields.

Also, I can't seem to make @Model work in WebMatrix. Any further help you can offer will be most welcome.  

Kindest regards. SJ
Bob LearnedCommented:
1) In order to use the @Model reference, you need a model declaration at the top of the view, with the type of object that you are passing in.

@model List<string>


@model UserData

2) In the controller, you would have a return like this:

return View(model);


return View("MyView", model);

3) When first starting out, I prefer to keep things simple.  It may help to remove the authentication checks, until you are comfortable with how the view is working.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sunny-jAuthor Commented:
perfect, thanks Bob, I have gone back to the drawing board and started over in MCV rather than continue with WebMatrix. Thanks for your help. Kind regards. SJ
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.