|
-
May 1st, 2007, 04:31 AM
#1
Thread Starter
Fanatic Member
distinct values in dataset
I have populated a dataset with one table.
The data in the table looks as follows:
Index1Name Index2Name City Value
Indexk Indexk city1 2
Indexk Indexk city1 3
Indexk Indexd city1 2
Indexk Indexy city1 1
Indexy Indexk city1 1
Indexx Indexk city1
Indext Indexq city1 5
Indexs Indexs city1 6
Now I would like to have an array which gets populated from the distinct values in columns of Index1Name and Index2Name
So the array should contain something like:
Indexd Indexk Indexy Indexx Indext Indexs Indexq
Thanks
-
May 1st, 2007, 04:35 AM
#2
Re: distinct values in dataset
How did you populate the dataset?
-
May 1st, 2007, 04:39 AM
#3
Thread Starter
Fanatic Member
Re: distinct values in dataset
SqlDataAdapter oDA = new SqlDataAdapter(comm);
DataSet dsData = new DataSet();
oDA.Fill(dsData, "datavalues");
-
May 1st, 2007, 04:41 AM
#4
Re: distinct values in dataset
Not exactly what i meant. I presume you had a SQL statement to select values?
Something like:
SELECT * FROM tableName
What you could do is to use the DISTINCT keyword in SQL to get distinct records which would save you lots of trouble.
-
May 1st, 2007, 04:42 AM
#5
Thread Starter
Fanatic Member
Re: distinct values in dataset
-
May 1st, 2007, 04:44 AM
#6
Thread Starter
Fanatic Member
Re: distinct values in dataset
Assuming I now have a dataset with the column values being distinct, how can I populate an array with the values please?
-
May 1st, 2007, 05:01 AM
#7
Re: distinct values in dataset
I would have a way to do it but really doubt it's the correct way. Just change the column name/value below
vb Code:
'Get number of results/rows returned by the dataset
Dim numResults As Integer = dsData.Tables("dataValues").Rows.Count - 1
Dim myResults(numResults) As String 'Dimension the array? Should this be +1
Dim Drow As DataRow
For i As Integer = 0 To numResults 'Go through each row
Drow = dsData.Tables("dataValues").Rows(i) 'assign current row
myResult(i) = Drow("Column").ToString 'Change column to your name
Next
My advice - wait until someone who knows about SQL stuff replies - I've only started it. It's most likely either badly flawed or really slow.
Edit: I found this example on the web. Kind of the same approach -
vb Code:
Dim arData() As String
Dim ds As New DataSet
' Fill your dataset in your own way here
ReDim arData(ds.Tables(0).Rows.Count) 'Is this correct?
For intCounter As Integer = 0 To ds.Tables(0).Rows.Count - 1
arData(intCounter) = ds.Tables(0).Rows(intCounter).Item(0).ToString
Next
Last edited by stimbo; May 1st, 2007 at 05:15 AM.
Reason: fix format
-
May 1st, 2007, 05:09 AM
#8
Re: distinct values in dataset
Is there a particular reason that you need the values in an array rather than just using then directly from the DataTable?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|