Я сделал небольшую заявку на покупку. Пользователь выбирает пару заказов и нажимает кнопку «Отправить по электронной почте». Электронная почта создается с данными из базы данных для этих указанных c заказов.
Вот как я делаю это прямо сейчас:
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 "";
}
}
}
Вывод, который отправляется по электронной почте, выглядит следующим образом:
Amazon, 2, 1, 2 / 20/2020 12:00:00 AM, kjhgg, 34.400, N, awefwef
Результат, который я хотел бы получить:
Ниже приведены ордера, требующие вашего внимания:
Как я могу заставить это работать как можно ближе? Любые идеи оценили