从单独的 DataRow[] 选择查询添加值
我试图从具有两个单独的 DataRow 的数据库中提取两个值并将它们添加在一起。出于某种原因,我只是对自己做错的事情一无所知,但是当我尝试将变量 p1 和 p2 添加到一起时,它们显示为未分配。
int p1;
int p2;
string count;
DataRow[] p1Count = dtCount.Select("ATTID = '" + att + " and WAVID = '20111'");
foreach (DataRow row in p1Count)
{
p1 = int.Parse(row["CountValue"].ToString());
}
DataRow[] p2Count = dtCount.Select("ATTID = '" + att + " and WAVID = '20112'");
foreach (DataRow row in p2Count)
{
p2 = int.Parse(row["CountValue"].ToString());
}
count = (p1 + p2).ToString();
sb.Append("<td nowrap ALIGN=CENTER colspan='1' bordercolor=#fff><strong>" + count + "</strong></td>");
I'm trying to pull two values from a db with two separate DataRows and add them together. For some reason I'm just going blank on what I'm doing wrong, but the variables p1 and p2 are showing as unassigned when I try to add them together.
int p1;
int p2;
string count;
DataRow[] p1Count = dtCount.Select("ATTID = '" + att + " and WAVID = '20111'");
foreach (DataRow row in p1Count)
{
p1 = int.Parse(row["CountValue"].ToString());
}
DataRow[] p2Count = dtCount.Select("ATTID = '" + att + " and WAVID = '20112'");
foreach (DataRow row in p2Count)
{
p2 = int.Parse(row["CountValue"].ToString());
}
count = (p1 + p2).ToString();
sb.Append("<td nowrap ALIGN=CENTER colspan='1' bordercolor=#fff><strong>" + count + "</strong></td>");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Sou你基本上改成了
这
解决了你的问题。这是常见的错误。
Sou you basically changed
to
This solved your problem. This is common mistake.