Gridview Duplicate removal.

G

Guest

Hello,

How would I remove duplicate rows from a dataset after it has already been
populated?

What would be the best way to check each row and delete duplicates while
leaving at least one unique of the duplicate rows?

Any Ideas?

Thanks in advance,

J
 
G

Guest

Oops,

My subject was probably misleading. Let me clarify.

My gridview in my asp.net 2.0 site is populated by a dataset not a
datasource.

Thanks,

j
 
Y

Yuan Ren[MSFT]

Hi J,

Thanks for posting!

For the current issue, I wonder the duplicated row is encountered in the
data base layer or the dataset layer?

In the dataset layer, there is not existed method to delete the duplicated
row. Since there are many duplicated rows such like duplicated primary key,
or duplicated one column, I think you can write your own method to
implement it in the dataset layer.

Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 
G

Guest

The data that I bring into the dataset is from two tables in my sql database
and it's a many to many relationship. I use an sql join statement and when
I do I end up with the following:

(PartNumber Column)
10024
10024
10024
10025
10025
10067
10067
10067

What I want it to look like is this:

10024
10025
10067

I am not familiar enough with SQL statements to fix this problem in the sql
join statement so I figured I could just remove the extra rows after the
fact in either the dataset or the Gridview.

Thanks,

J
 
Y

Yuan Ren[MSFT]

Hi J,

Thanks for your reply!

As I replied in the pervious thread, you need write your own method for
deleting the duplicated row. For example, you can read the row from the
current dataset. Then, you judge whether the next row is duplicated with
the current. If this is true, you get rid of the current row and read the
next. After this judgment, you can put the data to a new dataset and bind
the dataset with the GridView control.

Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 
G

Guest

Oh, I get it. That makes perfect sense. I did not gather that from your
last post but I understand clearly now.

Will that way of doing it be the least processor intensive?
In some instances there could be over 10,000 or more rows.

I wish I was more familiar with SQL Statements because I am sure that all
this could be done before hand when the data is called from the database. I
just dont understand how to do that.

I will definantly try the two dataset approach and let you know how that
works out.

Regards,

J
 
Y

Yuan Ren[MSFT]

Hi J,

Thanks for your reply!
"Will that way of doing it be the least processor intensive?"
Unfortunately, I think the current method will take more time to execute
when there are more rows in the dataset. So, I think you can post a new
thread to the SQL newsgroup if you think the performance is the key point.
Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 
G

Guest

Yuan,

Thanks for the response. I posted a thread there and am waiting on a
response.

Thanks again!

J

"Yuan Ren[MSFT]" said:
Hi J,

Thanks for your reply!
"Will that way of doing it be the least processor intensive?"
Unfortunately, I think the current method will take more time to execute
when there are more rows in the dataset. So, I think you can post a new
thread to the SQL newsgroup if you think the performance is the key point.
Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 
Y

Yuan Ren[MSFT]

Hi J,

You are welcome! If you have any further information related to this
problem, please feel free to post here. Thanks very much and looking
forward to hearing from you.

Yuan Ren [MSFT]
Microsoft Online Support
 
B

Bill Gregg

Yuan,
You could put the keyword "distinct" after your select and before
your columns in your SQL statement. This will remove all the duplicated
rows.

Bill Gregg
 
Y

Yuan Ren[MSFT]

Hi J,

Thanks for your reply!

First of all, thanks for Bill's reminder. Since I don't use the SQL Server
with a long time, I forget there is the "distinct" keyword is more
appropriate at the current stage. For example, there is a table likes below:
num name
1 a
1 a
2 a
2 b
2 b

So, if you use the statement below:
select distinct * from tblduplicated

You will get the result:
1 a
2 a
2 b

Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top