Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selecting specific User

I am trying to make an app that shows a users past expenses with C# querying a SQL Database.

I have a program that shows the user their current expenses.

They have to login using a unique username and password. When logged in, they should see only their expenses from the expenses table.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am currently using:

Select * from ExpensesTbl

Which shows everything, including other users information. I believe I need to use a WHERE clause, but I am unsure what it would look like as Im not sure what user is logged in.

In example, table Expenses currently has two users (A and B).

Can someone point me to how I can get just the information that pertains to only the logged user, instead of the information of all users?

>Solution :

The solution for this is using IDs on each user, on ExpensesTbl create a Foreign Key that binds the ID with the information of this user on ExpensesTbl, then just do a

SELECT * FROM WHERE ExpensesTbl.user_id = LoggedUser.id

Please, take a read at those documents:

https://www.w3schools.com/sql/sql_foreignkey.asp

https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading