显示当前用户的数据 [英] Showing Current User's Data

查看:94
本文介绍了显示当前用户的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用asp.net开发客户在线订购系统.

我的项目中有两组用户,一组是Administrator,另一组是普通用户.

我创建了两个表用户和订单".

1.用户表由列(用户名,用户名,密码等)组成.

2.订单表由各列组成(订单ID,订单名称,用户ID)

通过将用户表中的UserId指定为主键,将外键指定为Order表中的UserId,我链接了用户表和订单表这两个表.

一旦普通用户进入系统,他就应该能够创建他的订单.

但是我如何才能只查看他在asp.net中提交的订单?.

请对此进行指导.

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.

推荐答案



我假设您正在使用带有存储过程/查询的SQL数据库来显示数据.

在存储过程/查询中,您可以将变量"@UserID"从ASP.Net传递给SQL存储过程/查询,并在查询中添加以下代码:WHERE UserID = @UserID.

谢谢
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,


每当用户登录时,仅检索特定的用户订单.

喜欢.

在page_load事件中,

您将从登录页面获得当前的用户ID.因此,在page_load中有一个sqlCommand,该命令以userid为参数并检索特定用户的订单,并将其填写在datatable/gridview中.

Page_load
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
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());


//然后执行并填充到数据表/数据集中.

另外,如果您将UserId作为会话变量作为字符串传递,则必须对其进行更改


//then execute and fill into datatable/dataset.

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

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);




关于您的其他问题,每当您尝试保存新订单时,您都必须传递3个参数,包括USerId,这样它就不会为空.您可以使用以上代码在Order插入方法期间添加GUID参数




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


这篇关于显示当前用户的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆