Click here to Skip to main content
12,815,057 members (40,341 online)
Rate this:
Please Sign up or sign in to vote.
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());
        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();
        GridView1.DataSource = ds;
        SqlDataReader dr = cmd.ExecuteReader();
        DataTable tb = new DataTable();

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 7-May-12 22:42pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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); 

sb.ToString() will be included in email body
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 10 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100