Solved

how to run Distinct query on DataTable?

Posted on 2011-03-11
5
653 Views
Last Modified: 2012-06-27
Hi, I have created DataTable “dt1” programmatically and enter query results in that datatable “dt1”.
Below is the code:
string strquery = "SELECT Name, Phones FROM Directory";
SqlCommand cmd = new SqlCommand(strquery, connection);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt1 = new DataTable();
da.Fill(dt1);
---------------------------------------------------------------------
Now, I want to run Distinct query on one of the column “Phone” or Name and result should get store in another datatable.

How it can be done?

Regards,  
0
Comment
Question by:prdeshpande
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 400 total points
ID: 35107660
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 400 total points
ID: 35107666
HOW TO: Implement a DataSet SELECT DISTINCT Helper Class
http://support.microsoft.com/kb/326176
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 400 total points
ID: 35107671
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 400 total points
ID: 35107673
0
 
LVL 11

Assisted Solution

by:Sudhakar Pulivarthi
Sudhakar Pulivarthi earned 100 total points
ID: 35108374
Hi

// Get the distinct values applied on the column
string[] columns = {"Phone"};
DataTable distinctTable = dataTable.DefaultView.ToTable(true, columns);
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 53
c# DateTime Format validation 4 68
ASP.NET data base connection 35 37
C# LINQ 5 24
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question