Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900