如何将数据库中的多个数据存储在同一个文本框中?c#
本文关键字:文本 同一个 存储 数据库 数据 | 更新日期: 2023-09-27 18:28:45
您好,感谢您查看我的问题!我在从数据库中获取多个数据时遇到了一点问题。我试图在一个文本框中显示多个数据,当然它不会允许我这样做。
我的代码:
string authorised = "notReviewed";
SundownDatabaseEntities5 dbb = new SundownDatabaseEntities5();
System.Windows.Forms.Form ff = System.Windows.Forms.Application.OpenForms["Login"];
int idd = Convert.ToInt32(((Login)ff).idTb.Text);
var getrecordd = dbb.Holidays.Where(a => a.Id == idd).SingleOrDefault();
if (getrecordd.Authorised == authorised)
{
holidaysAuthorisedTb.Text = "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...";
}
FirstOrDefault();
得到它找到的第一个数据,但我需要它们。我该如何制作它,以便它显示多个数据而不是一个数据?谢谢大家!
例如文本框:
您的假期申请(" + getrecordd.Datefrom + " - "+getrecordd.Dateto+")
已发送。正在等待经理批准…
您的假期申请(" + getrecordd.Datefrom + " - "+getrecordd.Dateto+")
已获得授权。
您可以获取所有记录,然后使用foreach
。
var getrecordds = dbb.Holidays.Where(a => a.Id == idd).ToList();
foreach (var getrecordd in getrecordds)
{
if (getrecordd.Authorised == authorised)
{
holidaysAuthorisedTb.Text += "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it...";
}
else
{
holidaysAuthorisedTb.Text += "Your holiday request (" + getrecordd.Datefrom + " - "+getrecordd.Dateto+") has been sent. Waiting for manager to authorise it..."
}
}
或使用ForEach
方法
dbb.Holidays.Where(a => a.Id == idd).ForEach ( x =>
{
if (x.Authorised == authorised)
{
holidaysAuthorisedTb.Text += "Your holiday request (" + x.Datefrom + " - "+x.Dateto+") has been sent. Waiting for manager to authorise it...";
}
else
{
holidaysAuthorisedTb.Text += "Your holiday request (" + x.Datefrom + " - "+x.Dateto+") has been sent. Waiting for manager to authorise it..."
}
});