?
Solved

how to run Distinct query on DataTable?

Posted on 2011-03-11
5
Medium Priority
?
657 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 1600 total points
ID: 35107660
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1600 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 1600 total points
ID: 35107671
0
 
LVL 53

Assisted Solution

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

Assisted Solution

by:Sudhakar Pulivarthi
Sudhakar Pulivarthi earned 400 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 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