如何在电子邮件正文中发送数据库字段值 [英] How do I send database fields value in email body

查看:154
本文介绍了如何在电子邮件正文中发送数据库字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有活动表

i希望在电子邮件正文中发送活动详情

它无效并显示错误:

i have event table
i want to send event details in email body
it is not working and displaying error :

Object reference not set to an instance of an object





我尝试过:





What I have tried:

protected void send(object sender, EventArgs e)
   {
       studentDataContext dx = new studentDataContext();
       s_event eve = new s_event();

       int st = Convert.ToInt16((Request.QueryString["e_id"]));
       var log = (from s in dx.s_events
                  where s.e_id == st
                  select new { s }).FirstOrDefault();

       foreach (GridViewRow row in GridView1.Rows)
       {
           if (row.RowType == DataControlRowType.DataRow)
           {
               if ((row.FindControl("CheckBox1") as CheckBox).Checked)
               {
                   string name = row.Cells[0].Text;
                   string email = row.Cells[1].Text;
                   MailMessage mail = new MailMessage();
                   mail.To.Add(email);
                   mail.From = new MailAddress("mymail@gmail.com");
                   mail.Subject = "Event Details";
                   mail.Body = log.s.e_name;
                   mail.IsBodyHtml = true;
                   SmtpClient smtp = new SmtpClient();
                   smtp.Host = "smtp.gmail.com";
                   smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
                   smtp.EnableSsl = true;
                   smtp.Port = 587;
                   smtp.Send(mail);
               }
           }
       }
   }

推荐答案

1。
var log = (from s in dx.s_events
                 where s.e_id == st
                 select new { s }).FirstOrDefault();



可能没有针对您身份的任何记录。



2.


there might not be any record available against the id you've.

2.

int st = Convert.ToInt16((Request.QueryString["e_id"]));



检查您是否在此处收到有效值。

3.


Check if you are receiving valid values here.
3.

mail.Body = log.s.e_name;



检查log.s是否为空。


Check if "log.s" is not null.


这篇关于如何在电子邮件正文中发送数据库字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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