如何通过电子邮件从数据表发送数据? [英] How to send data from a datatable through email ?

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

问题描述

大家好!!!

我想通过电子邮件将数据集中的数据发送给客户.请告诉我该怎么做.

到目前为止,我已经做了很多

HI all!!!

I want to send data from a dataset through email to the customer. Please tell me how to do it.

I have done this much so far

private void databind()
{
    int id = Convert.ToInt32(Request.Cookies["Ship"]["OrderID"].ToString());
    con.Open();
    SqlCommand cmd= new SqlCommand("Select a.OID,a.PID,a.OPQuantity,a.PPrice,a.OPTotalPrice ,b.PName, (a.OPQuantity * (b.PTax/100 *a.PPrice)) as Tax from OrderProducts a,Products b where a.OID=''" + id + "'' and a.PID=b.PID", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    SqlDataReader dr = cmd.ExecuteReader();
    DataTable tb = new DataTable();
    tb.Load(dr);

    con.Close();
}



此步骤后我该怎么办?我的意思是如何通过电子邮件从此数据表发送数据

我已经完成了邮件发送部分.我只需要知道如何发送此数据



What should i do after this step ?? I mean how to send the data from this datatable through email

I have done the mail sending part . I only need to know how to send this data

推荐答案

You can render the gridview in HTML and send it as email body
StringBuilder sb = new StringBuilder(); 
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw); 
GridView1.RenderControl(hw);

sb.ToString() will be included in email body


我只需要知道如何发送此数据
电子邮件文本位于正文"属性中.

现在,您需要定义所有如何或以什么方式发送电子邮件.发送数据表没有任何意义.您必须以某种可读/可理解的格式格式化数据.

使用值表单数据表在其周围添加文本.形成完整的字符串,然后将其传递给电子邮件正文.
I only need to know how to send this data
Email text goes in ''Body'' property.

Now, you need to define how or what all you want to send in an email. Sending a datatable does not make any sense. You have to format the data in some readable/understandable format.

Add a text around it with value form datatable. Form the complete string and then pass it on to body of email.


这篇关于如何通过电子邮件从数据表发送数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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