简体   繁体   中英

how can i get the description of the user who is logged in at that moment using two different database table?

tblUsers

ID | username | password 
---+----------+-----  
1  | admin    | admin
2  | test     | test

tblDescription

descId | userID | description
-------+--------+-------------
  1    |   2    | this is for the test description
  2    |   1    | this is for the admin description

I have tried to build my database a little bit up.

I have created two different tables in my SQL database ( tblUsers and tblDescription ) and of course every user has an id

But what I want to do is when a user logs in ,

it will check the id of the user who is logged in and display the description.

I've been able to create the login with forms authentication in c# but I can't figure out how to get the description of the user?

I've done a couple research as I'm new to database but I still couldn't get it

Can I get some help? Thanks in advance.

With an INNER JOIN on the tblDescription based on ID ? Take a look here: https://www.w3schools.com/sql/sql_join_inner.asp . Have fun

When you say that you are Authenticating its basically you are calling a service which gives you some data , in this token or a response telling that the user has logged in . In your service you would be accessing database to query some details (user_id , password) , in this level (service) try to make a db call in the same session to fetch the user details from your database (Any table) .

For that you can use Joins in your query to retrieve from multiple tables .

If any queries , do comment and i will edit the answer if needed .

The way to do this as you've described is to use a trigger .

When you say you want the description, do you mean you want the username of the person who logged in or changed something? If so use something like this?

CREATE TRIGGER tr_update_paid ON UnPaidFees2017
AFTER UPDATE
AS
BEGIN


UPDATE UnPaidFees2017
SET DateChanged = GETDATE(), [User] = USER_NAME()
FROM UnPaidFees2017, inserted
WHERE UnPaidFees2017.ID = inserted.ID

END

That is an example I used before. You can change it up a bit.

on page_load event use query

select Description from tbl_description where UserID=Session["UserID"];

Maintain session at login page and use that session to fetch the description like this and show wherever you want hope this will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM