从单独的 DataRow[] 选择查询添加值

发布于 2024-12-20 04:43:38 字数 775 浏览 2 评论 0原文

我试图从具有两个单独的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-12-27 04:43:38

Sou你基本上改成了

int p1;
int p2;

int p1 = 0;
int p2 = 0;

解决了你的问题。这是常见的错误。

Sou you basically changed

int p1;
int p2;

to

int p1 = 0;
int p2 = 0;

This solved your problem. This is common mistake.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文