c# 将mysql当前结果与行中的下一个结果进行比较

发布于 2024-10-10 08:42:51 字数 916 浏览 5 评论 0原文

为了迭代我的结果集(列表列表),我当前正在使用:

    foreach (IELog ieLog in emailAttach)
    {
        logAttachment += ieLog.FirstName + "," + ieLog.LastName +
             "," + ieLog.Building + "," + ieLog.Room + "," + ieLog.Ingresstime + "," 
             + ieLog.Egresstime + "\n";
     }

我想将 ieLog.FirstName 与行中的下一个和图像进行比较,它会像这样工作,只是我的语法是错误的。

n = 0;
while (emailAttach.FirstName [n] == emailAttach.FirstName[n++] {
     do something;
    }

结果集如下所示:

Person |登录 |注销

约克亨特超时 约克亨特超时

约克亨特超时

约克亨特

超时

迈克亨特超时

迈克亨特

超时 迈克亨特

超时 迈克亨特超时

我的目标只是一次的名字

约克亨特超时

       intime outtime

       intime outtime 

       intime outtime   

迈克亨特超时超时

       intime outtime 

       intime outtime 

       intime outtime 

谢谢您的帮助!

To iterate through my result set, a lists of lists, I'm currently using:

    foreach (IELog ieLog in emailAttach)
    {
        logAttachment += ieLog.FirstName + "," + ieLog.LastName +
             "," + ieLog.Building + "," + ieLog.Room + "," + ieLog.Ingresstime + "," 
             + ieLog.Egresstime + "\n";
     }

I would like to compare ieLog.FirstName with the next one in line and image it would work something like this, just my syntax is wrong.

n = 0;
while (emailAttach.FirstName [n] == emailAttach.FirstName[n++] {
     do something;
    }

The result set looks like:

Person | Login | Logout

York Hunt intime outtime

York Hunt intime outtime

York Hunt intime outtime

York Hunt intime outtime

Mike Hunt intime outtime

Mike Hunt intime outtime

Mike Hunt intime outtime

Mike Hunt intime outtime

and I'm aiming for just the name once

York Hunt intime outtime

       intime outtime

       intime outtime 

       intime outtime   

Mike Hunt intime outtime

       intime outtime 

       intime outtime 

       intime outtime 

Thank you for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

青萝楚歌 2024-10-17 08:42:52

假设您可以使用 LINQ(至少在客户端),您应该只使用 source.GroupBy(x => x.FirstName) 将相同名称的条目分组在一起。

Assuming you have LINQ available to you (at least at the client) you should just use source.GroupBy(x => x.FirstName) to group entries for the same name together.

放肆 2024-10-17 08:42:52

您可以在 MySQL 中执行此操作。
http://www .mysqlfaqs.net/mysql-faqs/SQL-Statements/Select-Statement/DISTINCT-在 MySQL 中工作

SELECT DISTINCT FirstName, LastName, Building, Room, Ingresstime, Egresstime FROM table

You could do this in MySQL instead.
http://www.mysqlfaqs.net/mysql-faqs/SQL-Statements/Select-Statement/How-does-DISTINCT-work-in-MySQL

SELECT DISTINCT FirstName, LastName, Building, Room, Ingresstime, Egresstime FROM table
草莓酥 2024-10-17 08:42:51

您正在尝试获取 emailAttach 内第 n 项的 FirstName 属性。

换句话说,emailAttach[n].FirstName

另外,您需要将 n++ 更改为 ++n

You're trying to get the FirstName property of the nth item inside emailAttach.

In other words, emailAttach[n].FirstName.

Also, you need to change n++ to ++n.

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