0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
T Gabe
  • 15
  • 8

4 Answers4

0

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

  • i used the inner join and it worked in the sql , if i want to implement it to c#, do i use sqldataadapter of sqlcommand? – T Gabe Jun 22 '17 at 15:20
  • take a look here : https://stackoverflow.com/questions/6569012/data-adapter-vs-sql-command – Daniel Tomuta Jun 22 '17 at 15:25
  • this is what i have, "select userdesc.dealer_discription from userdesc inner join tblUsers on userdesc.UserId = tblUsers.Id" and after i execute i get all the discription, how can i specify for just one ID? – T Gabe Jun 23 '17 at 04:43
  • WHERE ID = 1 for example see @Peter example – Daniel Tomuta Jun 23 '17 at 09:50
0

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 .

Aakash Uniyal
  • 1,519
  • 4
  • 17
  • 32
  • and do i use sqlcommand to write the query or sqldataadapter? – T Gabe Jun 22 '17 at 15:19
  • you can use multiple approaches to query from DB in your asp.net app , yes you can use sqlDataAdapter , EntityFramework , etc . – Aakash Uniyal Jun 22 '17 at 15:22
  • http://csharp-station.com/Tutorial/AdoDotNet/Lesson04 This may help you – Aakash Uniyal Jun 22 '17 at 15:25
  • this is what i have, "select userdesc.dealer_discription from userdesc inner join tblUsers on userdesc.UserId = tblUsers.Id" and after i execute i get all the discription, how can i specify for just one ID? – T Gabe Jun 23 '17 at 04:43
  • In the end of the query write a "where" clause , tblUserts.Id = "user id which u want to search" – Aakash Uniyal Jun 23 '17 at 04:45
0

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.

Peter
  • 51
  • 5
  • this is what i have, "select userdesc.dealer_discription from userdesc inner join tblUsers on userdesc.UserId = tblUsers.Id" and after i execute i get all the discription, how can i specify for just one ID? – T Gabe Jun 23 '17 at 04:43
0

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

  • this is what i have, "select userdesc.dealer_discription from userdesc inner join tblUsers on userdesc.UserId = tblUsers.Id" and after i execute i get all the discription, how can i specify for just one ID? – T Gabe Jun 23 '17 at 04:41
  • well, if u are using asp.net with C# then maintain a session in login page like `SqlDataAdapter da=new SqlDataAdapter("select * from tblUsers where username='"+txtuserName.Text+"' and username='"+txtpassword.Text+"'",yourConnectionString); DataTable dt=new DataTable(); da.fill(dt); if(dt.rows.count>0){ //maintain session over here Session["userID"]=dt.row[0]["ID"]; Redirect to your page }` select userdesc.dealer_discription from userdesc inner join tblUsers on userdesc.UserId = tblUsers.Id where tblUsers.Id=Session["UserID"]; hope this will help now – Shayan Hafeez Jun 23 '17 at 08:44