gpt4 book ai didi

c# - 包含 SQL 的电子邮件

转载 作者:搜寻专家 更新时间:2023-10-30 21:40:43 24 4
gpt4 key购买 nike

我有一个名为“lnkupdate_click”的按钮,当您单击它时,它所做的基本上就是访问一个名为“tbl_security”的表,然后它将用一个随机的 4 位数字更新字段“pass”,其中字段“patrol”= 1 或真。

示例如下;

Code    Pass   Patrol
TES 1234 1
ASD 4321 1
MOR 6789 1
SAI 0959 1

我坚持的一点是:我希望它从这里做的就是通过电子邮件从数据库发送更新的信息。所以基本上是为我生成一封包含上表中所有信息的电子邮件。但是,我的“foreach”循环下方不断出现一条红线,并显示此错误消息。

“foreach 语句不能对‘int’类型的变量进行操作,因为‘int’不包含‘GetEnumerator’的公共(public)定义”

我的代码如下:

protected void lnkUpdate_Click(object sender, EventArgs e)
{


{
string queryUpdateAllFields;
string queryGetAllUpdatedField;
StringBuilder sb = new StringBuilder();

queryGetAllUpdatedField = @"update tbl_Security set
Pass = round(rand(CAST(CAST(NEWID() AS VARBINARY(4)) AS SMALLINT))* 9000,0) + 1000
WHERE Patrol = 1";

queryGetAllUpdatedField = @"SELECT Code, Pass, Patrol
FROM tbl_Security
WHERE Patrol = 1";

var random = new Random();

//queries to update and retrieve
SqlHelper.ExecuteSqlNonQuery(queryUpdateAllFields);

var results = SqlHelper.ExecuteSqlNonQuery(queryGetAllUpdatedField);


//loop over the results and append to StringBuilder instance.
sb.Append("Below are all the fields that have been updated: <br /><br />");

foreach(var r in results)
{
sb.AppendLine("<hr />");
sb.AppendLine("Code: " + r.Code + " Pass: " + r.Pass + " Patrol: " + r.Patrol); //for Patrol
}



//Email showing all updated pass's with codes
MailAddress to = new MailAddress("");
MailAddress from = new MailAddress("");
MailMessage message = new MailMessage(from, to);
message.Subject = "Subject Line Here";
message.Body = sb.ToString(); //attach StringBuilder - This will be built up of all the rows updated in the DataBase

SmtpClient mailClient = new SmtpClient();
mailClient.Port = 25;

//finally send message here
mailClient.Send(msg);

}
}

最佳答案

ExecuteSqlNonQuery返回 int 而不是我认为您假设的集合。

关于c# - 包含 SQL 的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13976596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com