I have made a small purchasing application. The user selects a couple of Orders and clicks 'SEND EMAIL'. Email gets created with data from the database for those specific orders.
This is how I am doing it right now:
string mailbod = "Following are Orders that need your attention: ";
mailbod=od.mailbody(orderid,mailbod);//Calling the method that sets up the string
public string mailbody(List<int>oids,string mailbod)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
string output = "";
using (SqlConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("TESTDB")))
{
StringBuilder sb = new StringBuilder("Select Distinct a.VEND_NAME,b.* from dbo.Purch_Vendor a inner join dbo.purch_order b on a.VENDOR_ID=b.VENDOR_ID left join dbo.purch_item c on b.ORDER_ID=c.ORDER_ID Where ");
if (oids.Count > 0)
{
foreach(int x in oids)
{
sb.Append("b.ORDER_ID" + "=" + x + " OR ");
}
sb.Length--;
sb.Length--;
sb.Length--;
SqlCommand command = new SqlCommand(sb.ToString(), connection);
SqlDataAdapter sqlDataAdap = new SqlDataAdapter(command);
DataTable dtRecord = new DataTable();
sqlDataAdap.Fill(dtRecord);
foreach (DataRow x in dtRecord.Rows)
{
//' Loop through each column. '
for (int i=0;i<dtRecord.Columns.Count; i++)
{// ' Output the value of each column's data.
sw.Write(x[i].ToString() + ", ");
}
output = sw.ToString();
//' Trim off the trailing ", ", so the output looks correct. '
if (output.Length > 2)
{
output = output.Substring(0, output.Length - 2);
}
//' Display the row in the console window. '
Console.WriteLine(output);
}
return output;
}
else
{
return "";
}
}
}
The output that gets emailed looks like this:
Amazon, 2, 1, 2/20/2020 12:00:00 AM, kjhgg, 34.400, N, awefwef
The output I would like to get:
Following are the Orders that need your attention:
How can I get this to work as close as possible? Any ideas appreciated