Recordset给出非不同的值

时间:2012-08-31 06:02:22

标签: c# linq recordset

我有一部分代码,它返回非不同的值。

无论如何,我可以使用不同的函数来获取不同的值吗?

代码:

public static Recordset queryTestDirector(string projectName, string query)
  {
     Recordset result = null;
     /*Connect to Test director and pull down all the currently listed QC numbers*/
     TDConnection tdConnection;
     tdConnection = new TDAPIOLELib.TDConnection();
     tdConnection.InitConnection("http://***/qcbin/", "ABC", "");
     tdConnection.ConnectProject(projectName, "qc_manager", "");

     Command cmd;
     cmd = tdConnection.Command as Command;
     String qcIDQuery = query;
     cmd.CommandText = qcIDQuery;
     result = cmd.Execute() as Recordset;

     tdConnection.Disconnect();
     return result;

  }

问题是返回的结果给出了值: A,A,A,A,B,C,d

我只想要A,B,C,D

请建议。

3 个答案:

答案 0 :(得分:0)

将您的查询更改为

select distinct BG_USER_50 from BUG where BG_STATUS in ('In Progress','Fixed','Unit Testing','Ready For UAT') and BG_USER_50 is not null order by BG_BUG_ID desc

应解决您的问题

答案 1 :(得分:0)

没试过,但这可能会奏效。您首先必须将记录集转换为数据集

ds.Tables[0].DefaultView.ToTable(true,"BG_USER_50");

这是一个解释更多

的链接

http://www.c-sharpcorner.com/blogs/230/how-to-get-disticnt-rows-from-a-dataset-or-datatable.aspx

How to select distinct rows in a datatable and store into an array

答案 2 :(得分:0)

非常感谢你们的投入,这让我重新考虑了这个问题。

最后这个查询有效:

queryString = "select BG_USER_50, count(*) from BUG where BG_STATUS in ('In Progress','Fixed','Unit Testing','Ready For UAT') and BG_USER_50 is not null group by BG_USER_50 order by 1 desc"

我只需要一个Group by子句。