2

对于这个问题,感谢 Jim ,将两列中具有相同值的两行连接起来。但是我没有在 windows 窗体应用程序中使用下面的代码,连接没有实现。这是MySQL代码:

 SELECT MIN(id),
       fikraNo,
       maddeNo,
       GROUP_CONCAT(icerik ORDER BY id DESC SEPARATOR ' ')
FROM `table`
GROUP BY fikraNo, maddeNo 

这是我使用 MySQL 的搜索方法:

public static DataTable Results(string table, string columns, string words)
{
    var sb = new StringBuilder();
    //var pm = new SqlParameter();

    sb.Append("SELECT MIN(id) AS minID, name, surname, GROUP_CONCAT(events ORDER BY id ASC SEPARATOR ' ') AS allEvents FROM " + table + " ");
    if (!string.IsNullOrEmpty(words))
    {
        var column = columns.Split('+');
        for (var i = 0; i < column.Length; i++)
        {
            if (i == 0)
            {
                var word = words.Split(',');
                for (var j = 0; j < word.Length; j++)
                {
                    if (j == 0)
                    {
                        // one column, one word...
                        sb.Append("WHERE " + column[i].Trim() + " LIKE '%" + Strip(word[j].Trim()) + "%'");
                        //pm = new SqlParameter("@word", "%" + word[j].Trim() + "%");
                    }
                    else
                    {
                        // one column, more words..
                        sb.Append(" OR " + column[i].Trim() + " LIKE '%" + Strip(word[j].Trim()) + "%'");
                        //pm = new SqlParameter("@word", "%" + word[j].Trim() + "%");
                    }

                }
            }
            else
            {
                var word = words.Split(',');
                for (var j = 0; j < word.Length; j++)
                {
                    if (j == 0)
                    {
                        // more columns, one word...
                        sb.Append(" OR " + column[i].Trim() + " LIKE '%" + Strip(word[j].Trim()) + "%'");
                        //pm = new SqlParameter("@word", "%" + word[j].Trim() + "%");
                    }
                    else
                    {
                        // more columns, more words...
                        sb.Append(" OR " + column[i].Trim() + " LIKE '%" + Strip(word[j].Trim()) + "%'");
                        //pm = new SqlParameter("@word", "%" + word[j].Trim() + "%");
                    }

                }
            }
        }
    }
    sb.Append(" GROUP BY name, surname");

    var dt = SetDataset(CommandType.Text, sb.ToString(), null).Tables[0];
    return dt;
}

但是,不幸的是我的方法只带来了第一行。你能帮我吗,我该如何管理它?国王问候。

4

0 回答 0