【发布时间】:2016-08-16 10:03:31
【问题描述】:
我想给动态用户发邮件,根据参数as
row["userName"].ToString()
我在我的代码中使用了上面这样的代码,
foreach (var row in group)
{
sbodyMail += "<tr>" +
"<td style='width: 100px; height: 14px;background-color:" + strcolorDet + "'>" + row["userName"].ToString() + " </td> " +
"<td style='width: 100px; height: 14px;background-color:" + strcolorDet + "'>" + row["Doc_Type"].ToString() + " </td> " +
"<td style='width: 100px; height: 14px;background-color:" + strcolorDet + "'>" + row["CountofDocNo"].ToString() + " </td> " +
"</tr>";
}
sbodyMail += "</table><br>" + //close of header
"<b>THIS IS A SYSTEM GENERATED MAIL. PLEASE DO NOT REPLY </b>";
string strExp = "";
string startupPath = "";
List<string> ls_attach1 = new List<string>();
MailMessage mail = new MailMessage();
startupPath = Environment.CurrentDirectory;
strExp = "RAName = '" + group.Key + "'";
DataTable dtNew = ds.Tables[1].Select(strExp).CopyToDataTable();
DataSet dsNew = new DataSet();
dsNew.Tables.Add(dtNew);
ExcelLibrary.DataSetHelper.CreateWorkbook(startupPath + "\\Attachment\\Reminder_Sheet.xls", dsNew);
ls_attach1.Add(startupPath + "\\Attachment\\Reminder_Sheet.xls");
foreach (var attach in ls_attach1)
{
mail.Attachments.Add(new Attachment(attach));
}
ce.SendEmail(row["userName"].ToString(), "", "", "Information on documents for processing", sbodyMail, "AUTOSQL", "Powersoft", ls_attach1, "ConnectionString");
但我得到错误:
名称
row在当前上下文中不存在错误
【问题讨论】:
-
您能否发布完整代码,以便我们大致了解您在做什么?
-
由于
row是在foreach (var row in group)中定义的,所以不能在循环外使用。 -
@ekad:那么我该如何使用它??任何其他方式
-
将“foreach(var row in group)”更改为“foreach(var rowForEeach in group)”并相应地重命名。
-
将所有扩孔代码放入foreach循环中。