【问题标题】:How to retrieve one column value from one table using asp .net mvc 4如何使用asp .net mvc 4从一张表中检索一列值
【发布时间】:2014-10-20 20:28:36
【问题描述】:

我有一张表,我想从一列(mailid)中检索所有值。在表中,有两列可用,即 id 和 mailid。 我想向此列中所有邮件 ID 可用的人发送邮件。

               mstEmpAdmin m = new mstEmpAdmin();


                var m2=(from e in db.mstEmpAdmins
                 select new
                 {
                     txtEmpAdminEmailId = e.txtEmpAdminEmailId,
                 });
                CustomMailService mail = new CustomMailService();

                string Subject = "Domestic Travel Request";
                string Body = "Hi Sir/Madam,My ";
                mail.Mail(m2,Subject, Body);

形成上面的代码,它在最后一行显示错误,我想我会将所有邮件 ID 存储在一个对象中,然后我将在发送邮件时传递该对象。

我可以那样做吗?有什么解决办法吗?

【问题讨论】:

  • mail.Mail(m2.txtEmpAdminEmailId, Subject, Body);
  • 感谢您的快速回复,但上面一行显示错误
  • 对不起,您需要添加.FirstOrDefault(查询返回一个集合但您只想要一个值)
  • 没有 Stephen Muecke,我想要所有的非单一值......因为我需要向所有人发送邮件......
  • Mail的第一个参数接受什么?是收藏吗?逗号分隔列表?

标签: asp.net-mvc-4 email


【解决方案1】:

我得到了输出。

            List<mstEmpAdmin> adminlist = (from st in db.mstEmpAdmins
                                               select st).ToList();
                foreach (var item in adminlist)
                {

                    string Subject = "Request for Business Card";
                    string Body = "Hello Sir/Madam ," + "\n" + " " + bc.txtFirstName + " " + "You have requested for Business Card" + " " + "Total no of Quantity :" + bc.intQuantity + " ";
                    CustomMailService mail = new CustomMailService();

                    mail.Mail(item.txtEmpAdminEmailId, Subject, Body);
                }

【讨论】:

  • 现在我知道你真正想要什么了 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-12
  • 1970-01-01
  • 1970-01-01
  • 2020-06-14
相关资源
最近更新 更多