访问 LINQ 结果集中的不同列
我有一个使用 LINQ 从数据库返回多列的查询,
var donors = from d2 in db.Donors
where d2.Status == "Pending"
select new { donorID = d2.donorID, bloodGroup = d2.bloodGroup, contactNo = d2.contactMobile, status = d2.Status };
现在我想在访问 donors
结果集中的一列值的不同 Labels
中显示结果。
例如:
Label1.Text = 捐赠者ID; Label2.Text = BloodGroup;
...等等
请帮助我实现这一点。
I have a query which returns multiple columns from the database using LINQ
var donors = from d2 in db.Donors
where d2.Status == "Pending"
select new { donorID = d2.donorID, bloodGroup = d2.bloodGroup, contactNo = d2.contactMobile, status = d2.Status };
now I want to display the results in different Labels
accessing one column value from donors
resultset.
ex:
Label1.Text = donorID;
...and so on
Label2.Text = bloodGroup;
please help me achieve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要将标签设置为值,则需要一个单个记录。当前您正在选择一个记录序列。假设您只对第一个值感兴趣。您可以这样写:
如果您想显示所有捐赠者详细信息,您会需要更像网格的东西。
If you're going to set a label to a value, you'll need a single record. Currently you're selecting a sequence of records. Let's suppose you're only interested in the first value. You could write:
If you want to display all the donor details, you'll want something more like a grid.
如果你坚持保留标签,你可以这样做
If you insist in keeping the labels, you could do something like this