Write contents of dataset into email
-
Hi guys.. I have a console application developed on c# VS2003 which sends email based on the query check now when the query returns multiple rows i store them in a dataset can anyone kindly tell me how do i extract the contents from the dataset and paste it on the content of my email. Any help is highly appreciated.. Thanx inadvance, Tash
-
Hi guys.. I have a console application developed on c# VS2003 which sends email based on the query check now when the query returns multiple rows i store them in a dataset can anyone kindly tell me how do i extract the contents from the dataset and paste it on the content of my email. Any help is highly appreciated.. Thanx inadvance, Tash
Plain logic : Iterate over datset/datatable rows. Get data from each row format/align as your need. And append this in email body. Like
StringBuilder sb = new StringBuilder();
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName"].ToString());
}//format this sb acc. to your need
//put this sb in your email body -
Plain logic : Iterate over datset/datatable rows. Get data from each row format/align as your need. And append this in email body. Like
StringBuilder sb = new StringBuilder();
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName"].ToString());
}//format this sb acc. to your need
//put this sb in your email body -
Plain logic : Iterate over datset/datatable rows. Get data from each row format/align as your need. And append this in email body. Like
StringBuilder sb = new StringBuilder();
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName"].ToString());
}//format this sb acc. to your need
//put this sb in your email body -
<> wrote:
is it possible to display as the table
If by this you mean show in a tabular format like
Col1 Col2
1 A
2 BAs i said you have to format the o/p as you want to show.
foreach (DataColumn dc in ds.Tables["TableName"].Columns)
{
sb.Append(dc.ColumnName);
sb.Append(" ");
}//Column end
sb.Append(Environment.NewLine);
//Row data
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName1"].ToString().PadRight(20,' '));
sb.Append(item["columnName2"].ToString().PadRight(20,' '));
sb.Append(Environment.NewLine);
}May be their better way then this !! :)
-
Hi guys.. I have a console application developed on c# VS2003 which sends email based on the query check now when the query returns multiple rows i store them in a dataset can anyone kindly tell me how do i extract the contents from the dataset and paste it on the content of my email. Any help is highly appreciated.. Thanx inadvance, Tash
Most mail systems know how to handle HTML, so you could get a real table by adding some TABLE, TR, TD tags. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hi guys.. I have a console application developed on c# VS2003 which sends email based on the query check now when the query returns multiple rows i store them in a dataset can anyone kindly tell me how do i extract the contents from the dataset and paste it on the content of my email. Any help is highly appreciated.. Thanx inadvance, Tash
I usually write the data to an XML file and attach it. The receiver can then use XSLT to transform the data to HTML, CSV, etc.