Hello,
I have this data in a DataSet:
Year Account Amount
1995 1 999
1995 2 323
1995 3 321
1996 1 354
1996 2 434
I want to get the distinct number if years, in this instance 1995 and 1996
in one query. Is it possible please? Please note that the data is in a
DataSet, I can loop and use HashTable, but this is not a good way.
--
Mike 5 1744
Mike,
I believe this may be the sixth time I've seen this one in the last couple
of months!
Aside from jumping through programmatic hoops (such as with a Hashtable,
etc) the easiest way is to ensure your rows are distinct on the database side
with "SELECT DISTINCT"
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Mike9900" wrote: Hello,
I have this data in a DataSet:
Year Account Amount
1995 1 999 1995 2 323 1995 3 321 1996 1 354 1996 2 434
I want to get the distinct number if years, in this instance 1995 and 1996 in one query. Is it possible please? Please note that the data is in a DataSet, I can loop and use HashTable, but this is not a good way. -- Mike
Hello,
Thanks for the reply.
This is the best idea, but we need this data without distinct. But when it
is in the client, we need it this way.
--
Mike
"Peter Bromberg [C# MVP]" wrote: Mike, I believe this may be the sixth time I've seen this one in the last couple of months!
Aside from jumping through programmatic hoops (such as with a Hashtable, etc) the easiest way is to ensure your rows are distinct on the database side with "SELECT DISTINCT" Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Mike9900" wrote:
Hello,
I have this data in a DataSet:
Year Account Amount
1995 1 999 1995 2 323 1995 3 321 1996 1 354 1996 2 434
I want to get the distinct number if years, in this instance 1995 and 1996 in one query. Is it possible please? Please note that the data is in a DataSet, I can loop and use HashTable, but this is not a good way. -- Mike
You can create a Command object (OleDb or SQL) that has a CommandText property set to SELECT DISTINCT statement. Then you should execute DataReader to get desired data. Here’s an example how can you fill a ComboBox with distinct data (but in this case you must open a connection, it's not from dataset): - System.Data.OleDb.OleDbCommand cmdDistinct = new System.Data.OleDb.OleDbCommand();
-
-
cmdDistinct.CommandText = "SELECT DISTINCT DesiredColumn FROM DesiredTable";
-
cmdDistinct.Connection = myOleDbConnection;
-
-
myOleDbConnection.Open();
-
System.Data.OleDb.OleDbDataReader rdr = cmdDistinct.ExecuteReader();
-
-
while(rdr.Read())
-
{
-
myCombo.Items.Add(rdr.GetValue(0).ToString());
-
-
// or like this:
-
// myCombo.Items.Add(rdr["DesiredColumn"].ToString());
-
}
-
-
rdr.Close();
-
myOleDbConnection.Close();
Hello,
Thanks for the reply.
This is the best idea, but we need this data without distinct. But when it
is in the client, we need it this way.
--
Mike
Of course, you could always return a DataSet containing one table with
"distinct" and the other one for whatever reason you have to have it that way.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Mike9900" wrote: Hello,
Thanks for the reply.
This is the best idea, but we need this data without distinct. But when it is in the client, we need it this way. -- Mike
"Peter Bromberg [C# MVP]" wrote:
Mike, I believe this may be the sixth time I've seen this one in the last couple of months!
Aside from jumping through programmatic hoops (such as with a Hashtable, etc) the easiest way is to ensure your rows are distinct on the database side with "SELECT DISTINCT" Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Mike9900" wrote:
Hello,
I have this data in a DataSet:
Year Account Amount
1995 1 999 1995 2 323 1995 3 321 1996 1 354 1996 2 434
I want to get the distinct number if years, in this instance 1995 and 1996 in one query. Is it possible please? Please note that the data is in a DataSet, I can loop and use HashTable, but this is not a good way. -- Mike
If you wish to do it without a seperate query to the database, there is a
full helper routine here http://support.microsoft.com/default...b;en-us;326176
Cheers,
Greg Young
MVP - C# http://codebetter.com/blogs/gregyoung
"Mike9900" <Mi******@discu ssions.microsof t.com> wrote in message
news:2A******** *************** ***********@mic rosoft.com... Hello,
I have this data in a DataSet:
Year Account Amount
1995 1 999 1995 2 323 1995 3 321 1996 1 354 1996 2 434
I want to get the distinct number if years, in this instance 1995 and 1996 in one query. Is it possible please? Please note that the data is in a DataSet, I can loop and use HashTable, but this is not a good way. -- Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ben |
last post by:
This is a PHP / MySQL kind of question. I am making a script which
simply pulls information from a database and displays it on screen. BUT
there will be entries where fields could be the same, and I want to
eliminate the duplicate entries when it displays it on screen.
I would use,
SELECT DISTINCT 'address1' FROM orders
....which does work, but only gives me one field. I also need to get a
|
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b. Yahoo store was originally written in Lisp.
c. Emacs
The issues with these will probably come up, so I might as well
mention them myself (which will also make this a more balanced
|
by: Dianna |
last post by:
I don't understand why the dataview or the dataset does not have a 'Select Distinct' option. They both can do so much to filter the data except that. The article Microsoft has 326176 works, but not if you need to select distinct on multiple fields.
Does anyone have any suggestions
Thanks
Diann
|
by: Kelvin |
last post by:
Okay so this is baking my noodle. I want to select all the
attritbutes/fields from a table but then to excluded any row in which
a single attributes data has been duplicated.
I.E. Here's my table:-
ID Ref Name DATE
1 AAA Joe 1/2
2 BBB Ken 1/2
3 AAA Len 6/3
|
by: Fred Zuckerman |
last post by:
Can someone explain the difference between these 2 queries?
"Select Distinct id, account, lastname, firstname from table1"
and
"Select DistinctRow id, account, lastname, firstname from table1"
Thanks,
Fred Zuckerman
| |
by: orekinbck |
last post by:
Hi There
Our test database has duplicate data:
COMPANYID COMPANYNAME
1 Grupple Group
2 Grupple Group
5 Grupple Group
3 Yada Inc
4 Yada Inc
|
by: mcyi2mr3 |
last post by:
Hi
Help! Im stuck on a join query.
Im trying to get distinct (the same row returned only once) user_id and
forename from a tbl of users (they are always distinct) where user_id
in that tbl equals friend_id in another table friend_id, which 'should'
be unique ie there 'should' only be one row of a 'friend connection',
but in the case of bugs etc this might not be true, what i want to do
is select only the row of tblusers with the user...
|
by: srusskinyon |
last post by:
I need some help getting unique records from our database! I work for
a small non-profit homeless shelter. We keep track of guest
information as well as what services we have offered for statistical
purposes.
I've been using
Here's the situation:
I have two main tables:
|
by: Lacutas |
last post by:
Hi all,
I am having some problems using LINQ to access Distinct records from a Dataset. I have looked around and believe it should be as simple as added .Distinct() to my LINQ query below, though intellisense doesn't even give that option!
My DataSet has multiple tables, all populated with data. I have a table called DemographicCriteria which has the fields listed below.
CriteriaID
DemographicCode
InputID
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |