【问题标题】:How to compare two database table fields in asp.net如何比较asp.net中的两个数据库表字段
【发布时间】:2014-11-02 06:45:48
【问题描述】:

需要比较asp net中两个不同的表格单元格。一个表包含结果,如下所示

round id = 1 |
game1 = 25 |
game2 = 25 |
game2 = 10 |

round id = 2 |
game1 = 25 |
game2 = 0 |
game3 = 0 |

the user table goes as follows :

username = Mike |
round id = 2|
game1 = 25 |
game2 = 10 |
game3 = 0|

我希望这样,如果用户表中的roundid 与结果表中的一个匹配,则比较该轮游戏的值。因此,对于第 2 轮,如果 game1 匹配 results : totalscore =+ 1; 的 game1 如果它不匹配,它什么也不做,也不增加任何东西!最后在标签或文本框中显示总分如何在asp.net中做到这一点?

【问题讨论】:

  • 我在搞乱 sqldatasources @SagarPudi 所以后面真的没有代码我只需要知道一个方法,我可以搜索该方法的代码

标签: mysql sql sql-server asp.net-mvc


【解决方案1】:

首先,无论您如何根据设计范式(MVC、MVP、MVVM 等)组织应用程序,您都应该始终处理数据和events 而不是 UI 元素。也就是说,UI 元素显示数据,UI 事件通过事件绑定到数据集,因此 UI 元素简单地具体反映了抽象中正在发生的事情数据集的级别。

其次,您所谓的“用户”表不是用户表。它似乎是用户和轮次的组合,所以也许我们应该称它为AppUserRound 表。

所以,假设IList<Result> results 包含您的结果,IList<AppUserRound> userRounds 包含您的用户的回合。要通过RoundID 将这些表加入,请使用 Linq 形成一个“加入”表:

var query = from ur in userRounds
            join r in results on r.RoundID = ur.RoundID
            select new { ur.Usernqame, r.RoundID, r.Game1, r.Game2, r.Game3 };

显然,您的特定数据结构可能不同,但使用此连接表,您可以显示一个包含两个表中信息的列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    • 2016-04-03
    相关资源
    最近更新 更多