Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm retrieve the data from sql server and store it in datagridview . After this I need to send mail to my client . whatever data is in datagridview , I need to sent the datagridview data's to client as message . I tried my best but i cant add datagridview data in message. below is my code pls help me...


loading datagridview from sql server


DataTable datatable = new DataTable();
     Connection();
     datatable.Load(new SqlCommand("select * from StudentMarksHistory", cs).ExecuteReader());
     dataGridView1.DataSource = datatable.DefaultView;
     cs.Close();



sending mail to client

C#
foreach (DataGridViewRow row in dataGridView1.Rows)
          {
                mailBody +="<tr>";
                foreach (DataGridViewCell cell in row.Cells)
                {
                   mailBody +="<td stlye='color:blue;'>" +cell.Value + "</td>";
                }
                mailBody +="</tr>";
          }
          mailBody +="</table>";

          //your rest of the original code
          mail.Body = mailBody;
string mailBody = "<table width='100%' style='border:Solid 1px Black;'>";
Posted
Comments
[no name] 24-May-13 9:18am    
And what exactly is wrong with the code that you have? "but i cant" is not helpful or informative. First thing I see is that you are declaring "mailBody" after you have already used it.
David_Wimbley 24-May-13 11:18am    
I also see that there is no code to send the mail, first step to sending mail is to .Send() it
[no name] 24-May-13 14:16pm    
Not to mention declaring a server, defining the port, address and all that other completely unnecessary stuff.... :-)
Varun Sareen 27-May-13 1:25am    
Dear Friend,

As per your code it seems to me that you are doing the right way. For your clear understanding for the concept of sending a Mail from the girdview to email. I am posting an answer.

Kindly check.

Regards

Varun Sareen

1 solution

Dear Friend,

About 55,000,000 results sending grid data to email?

Please don't forget to mark this as your answer if it helps you out.

Regards

Varun Sareen
 
Share this answer
 
Comments
KalaiPondy 27-May-13 2:41am    
i mentioned That i need it in winform c# ?
Then Y u given the asp project sample in google...
Varun Sareen 27-May-13 2:56am    
Dear Kalai,

If you see all the links, there are links for win application also.

http://www.codeproject.com/Articles/23640/How-to-send-DataGridView-contents-by-email

My intention was to tell you that if you search google everything can be find out.

I hope that if you look at my link once again you will get the answer.

Regards

Varun

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