06 February 2017

Filtering The Result Based On Specific User

In one of my seminars, one student asked me how to filter the result of database query to specific user and display it in GridView.

Okay, here's what we did:


Assuming that  we have a table named tbl_Profile with columns Name (varchar), Age (int), Address (varchar), Birthdate (date), and UserId (uniqueidentifier)

Now, if we want to display the records that belong to the specific user, we simply add a Label on the page and set its visibility to false.

ex. Label1.visible = false;

Then in our query, we filter the result using WHERE clause like this:


SELECT Name, Age, Address, Birthdate FROM tbl_Profile WHERE UserId=@UserId

No comments:

Post a Comment