INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to remove dublicate records from a datatable

How to remove dublicate records from a datatable

(OP)
Hello people,
I have got a datatable.

How do I delete dublicate records?

Thank you in advance

RE: How to remove dublicate records from a datatable

What sort of database?
Can you provide the table structure?

RE: How to remove dublicate records from a datatable

(OP)
here you go:

CODE --> VB.net

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim da As SqlDataAdapter
        Dim SQLStr As String
        Dim cnn As SqlConnection
        DataGridView1.DataSource = Nothing
        cnn = New SqlConnection(connectionString)
        cnn.Open()

        'Query för alla kolumner
        SQLStr = "SELECT " & _
                 "CAST (tt.OrderNr AS varchar(10)) + ' – ' + PostIt.Text AS 'New Column' " & _
              "FROM [myDB].dbo.OpusOrder as tt INNER JOIN" & _
              "[myDB].dbo.CompanyMain as c On tt.bolagsnr = c.id INNER JOIN" & _
              "[myDB].dbo.OpusOrderrow as ord On ord.ordernr = tt.ordernr INNER JOIN" & _
              "[myDB].dbo.PostIt as PostIt On PostIt.ordernr = tt.ordernr INNER JOIN" & _
              "[myDB].dbo.OrderCompanyLanguageName as snSrc ON ord.kallspraknr = snSrc.spraknr INNER JOIN" & _
              "[myDB].dbo.OrderCompanyLanguageName as snTrg ON ord.malspraknr = snTrg.spraknr"
        da = New SqlDataAdapter(SQLStr, TTCon)
     
                Dim myDatatable As New DataTable()
        da.Fill(myDatatable)
        For Each row As DataRow In myDatatable.Rows
            If Not row.Item(0).ToString().Contains("Language:") Then
                row.Delete()
            End If
        Next
        myDatatable.Columns(0).ColumnName = "Context Matches"


' I BELIEVE IT MUST BE HERE I MADE THE FUNCTION.
        DataGridView2.DataSource = myDatatable
      
    End Sub 

RE: How to remove dublicate records from a datatable

What we need is the list of columns in the table in which you have duplicates. Which column (if any) is the primary key. I'm guessing that you are using SQL Server.

RE: How to remove dublicate records from a datatable

(OP)
well I only have got one column and its called "Context Matches" I hope otherwise its just one column so (0)

RE: How to remove dublicate records from a datatable

So "Context Matches" is the column which contains duplicate entries?

Where does its data come from?

RE: How to remove dublicate records from a datatable

(OP)
is this what you mean?

CODE --> VB.net

da = New SqlDataAdapter(SQLStr, TTCon)
Dim myDatatable As New DataTable()
da.Fill(myDatatable) 

RE: How to remove dublicate records from a datatable

If you are referring to the query in your first post above, it doesn't contain a column called "Context Matches"

RE: How to remove dublicate records from a datatable

(OP)
yes of course.

I actually added SELECT DISTINCT seems to work so far. but always good to know how to make it anyway.

RE: How to remove dublicate records from a datatable

Yes DISTINCT should do the trick.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close