Click here to Skip to main content
15,891,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm developing a Customer online ordering system using asp.net.

There are two set of users in my project, one is the Administrator and the other is the normal user.

I created two tables Users & Orders.

1. User table consists of the columns (UserId, Username, Password etc.)

2. Order Table COnsists of the columns (OrderId, Order name,UserId)

I link two tables the User Table and order Table by specifying UserId in the User table as Primary key and foreign key as UserId in Order table.

Once a normal User looged in to the system, he should be able to create his orders.

But how can I make to view only his orders submitted by him in asp.net?.

Please guide me on this.
Posted

Hi,

I'm assuming you are using a SQL Database, with Stored Procedures/Query to display the data.

Within the Stored Procedure/Query you can pass a variable '@UserID' from ASP.Net to the SQL Stored Procedure/Query and within your query you add the following code: WHERE UserID = @UserID.

Thanks,
 
Share this answer
 
Whenever user logs in retrieve only particular user orders.

Like.

In page_load event,

You will have current user id from login page. So Have a sqlCommand in page_load which take userid as parameter and retrive orders for particular user and fill it in datatable/gridview.

Page_load
C#
Guid theGuid =//ur userid;
SqlCommand cmd=new SqlCommand("select * from Orders where UserId=@UserId",con);
command.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = System.Data.SqlTypes.SqlGuid.Parse(theGuid.ToString());

//then execute and fill into datatable/dataset.

Also incase if you pass UserId as session variable as string, you have to change it

C#
string theGuid =//ur userid;
SqlCommand cmd=new SqlCommand("select * from Orders where UserId=@UserId",con);
command.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = System.Data.SqlTypes.SqlGuid.Parse(theGuid);



Regarding ur other question, whenever u are trying to save new order, you have to pass 3 parameters including USerId, so that it wont be null, You can use the above piece of code for adding GUID parameters during Order insert method
 
Share this answer
 
v2
Comments
Member 9334466 4-Aug-12 6:58am    
Thank you Santhosh for your reply,

Currently I'm using "Unique Idientifier" as the data type. So, How would be the coding will be?

Also, in the Order table, the foreign key column of UserId is not updating with the primary key of column UserId in user Table. Once a user add an order, the value of UserId in Order table specified as "Null". How can i update this?
Santhosh Kumar Jayaraman 4-Aug-12 7:13am    
Updated the solution.Please check
Member 9334466 5-Aug-12 7:38am    
Hi Santhosh,

Can I know which command I need to enter in the area //ur userid; below?

Guid theGuid =//ur userid;
Santhosh Kumar Jayaraman 5-Aug-12 7:44am    
You said User Id is Guid right? Whatever value applicable for the particular user, The GUID from login page should be passed here
Member 9334466 6-Aug-12 6:57am    
Can you elaborate more on this command pls?

Guid theGuid =//ur userid;

As I'm using Visual Studio 2010. I have added the Login Name from the toolbox into the page. so, that once the user login to the system, his user name is visible on the page. DO I need to pass this on the above command? If yes, Pls indicate the command.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900