0

I have a part of code, which returns non distinct values.

Is there anyway, I could use a distinct function to the same to get distinct values?

Code:

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;

  }

The problem is the result returned gives values: A,A,A,A,B,C,D

I want only A,B,C,D

Please suggest.

Ashutosh
  • 25
  • 1
  • 12

3 Answers3

0

Changing your query to

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

should solve your problem

Justin
  • 4,002
  • 2
  • 19
  • 21
  • COMException was unhandled: Failed to Run Query – Ashutosh Aug 31 '12 at 06:17
  • I had tried that before, the point is actually querystring returns the CR numbers...and they are stored in the Recordset. I need to use distinct on the Recordset, which I have been searching for sometime now. – Ashutosh Aug 31 '12 at 06:18
0

Haven't tried it, but this might work. You'll first have to convert your recordset into a dataset

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

Here's a link explaining more

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

Community
  • 1
  • 1
Divi
  • 7,621
  • 13
  • 47
  • 63
0

Thanks a lot guys for your inputs, which made me rethink the query.

Finally this query works:

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"

I just needed a Group by clause.

Divi
  • 7,621
  • 13
  • 47
  • 63
Ashutosh
  • 25
  • 1
  • 12
  • Your question reads you want distinct from a recordset. Justin gave you the answer as per your question to get distinct from the database. Then Divi gave you the answer to get distinct from the recordset. Your answer does not match your question. – DarK Aug 31 '12 at 09:55
  • Dark, yes I never questioned Divi or Justin's logic. The logic was absolutely fine. The implementation was bothering me. And the question and answers are in sync. Please see Justin's and My answer. Both are the "queryString". Divi and Justin were spot on with their logic. – Ashutosh Sep 04 '12 at 03:14
  • I didn't down vote you. Just said that the question you asked did not match what you really wanted to do. Or at least, it lacked a lot of detail. And when given an answer, you rejected the answers to the question you were asking and came up with your own solution, which didn't match your question. – DarK Sep 04 '12 at 09:41