【发布时间】:2018-12-27 00:47:30
【问题描述】:
我正在尝试使用 Linq 在我的 c# windows 窗体项目中将数据从数据库加载到 RichTextBox(如图所示)。
我不知道我是否做得对,因为数据没有加载到 RichTextBox。请帮忙。
这就是我正在尝试的方式:
string idNr = txtIdcardNr.Text.Trim();
var CheckIfIdCardExist = (from u in db.Customer
where u.IdentityCardNr == idNr
select u).FirstOrDefault();
if(CheckIfIdCardExist != null)
{
String template =
@"Date\t\t{0}
Notes\t\t{1}
Staff\t\t{2}
*********\t\t{3}";
var notes = (from u in db.CustomerNotes
join em in db.Employee on u.StaffId equals em.EmployeeId
where u.CustomerId == CheckIfIdCardExist.CustomerId
select new {
Date = u.NoteDate,
notes = u.Notes,
employee = em.FirstName + " " + em.LastName
}).ToList();
foreach(var n in notes)
{
richTextBox1.Text = string.Format(template, n.Date, n.notes, n.employee);
}
【问题讨论】:
-
你没有说你不喜欢这是做什么的。但是,我建议在答案中尝试一下。
-
richTextBox1.Text =显然这条线会让你摆脱困境,不管其他任何问题,你只需添加最后一个注释 -
图片是你想看的吗?
-
@Ann L. 感谢您的回复,是的,我希望看到这样的图像
-
@TheGeneral 指出的问题是不是你只看到了最后的注释?如果是这样,我在下面提出了一个解决方案。
标签: c# winforms linq richtextbox