Search function duplicates data vb.net

I have a select query to search the data from access but the problem is that the search function duplicates each line (show the same line 2 times in DGV). Can anyone guide me to the problem thanks in advance.

    Dim sql = "SELECT A.* FROM  ((tblMatrice AS B INNER JOIN tblRefMatrice AS C ON B.strMatrice = C.strMatrice) INNER JOIN tblRefMatDetails AS D ON C.intIDref = D.intIDRef) LEFT OUTER JOIN tblDopages AS A on A.strMatrice = B.strMatrice where "

    cmd = New OleDbCommand(sql, myConnection)

    If CKBrefech.Checked = True Then
         sql = sql & "strRefEch = @Refech  AND "
    End If

    sql = sql & "strMethode = @Methode AND "

    sql = sql & "strPurif = @Purif AND "


    If CKBmatrice.Checked Then
         sql = sql & "A.strMatrice = @Matrice AND "
    End If

    sql = sql & "strMolecule = @Molecule AND "

    If CKBechprep.Checked Then
        sql = sql & "datDatePrepa >= @DatPrepa AND "
    End If
    If CKBechau.Checked Then
        sql = sql & "datDatePrepa <= @Datau AND "
    End If
    If CKBtrigprepa.Checked = True Then
       sql = sql & "strTrigPrepa = @Trigprep AND "
    End If
    If CKBtriganaly.Checked = True Then
       sql = sql & "strTrigAnaly = @Triganaly AND "
    End If
    If CKBappar.Checked = True Then
       sql = sql & "strNomTech = @Tech AND "
    End If
    If CKBnumappar.Checked = True Then
       sql = sql & "[strEquip(Appareil)] = @Equip AND "
    End If
    If CKBteneurmini.Checked = True Then
       sql = sql & "dblDopage > @TenMini AND "
    End If
    If CKBteneurmax.Checked = True Then
        sql = sql & "dblDopage < @TenMaxi AND "
    End If

    If GroupBox1.Enabled Then
        Try
            If CKBnomref.Checked Then
               sql = sql & "D.strReferentiel = @NomRef AND "
            End If
            If CKBniv1.Checked Then
               sql = sql & "D.strNIveau1 = @Niv1 AND "
            End If
            If CKBniv2.Checked Then
               sql = sql & "D.strNiveau2 = @Niv2 AND "
            End If
            If CKBniv3.Checked Then
               sql = sql & "D.strNiveau3 = @Niv3 AND "
            End If
            If CKBniv4.Checked Then
               sql = sql & "D.strNiveau4 = @Niv4 AND "
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End If

    ' Remove the last AND if any ....'
    If sql.EndsWith(" AND ") Then
        sql = sql.Substring(0, sql.Length - 4)
    End If
    ' Remove the WHERE if no textbox has been filled....'
    If sql.EndsWith(" WHERE ") Then
        sql = sql.Substring(0, sql.Length - 7)
    End If

    sql = sql & " ORDER BY datDatePrepa ASC "


    cmd.CommandText = sql
    cmd.Connection = myConnection
    Dim MyDataSet As New DataSet
    MyDataSet.Clear()
    da = New OleDbDataAdapter(sql, myConnection)
    da.SelectCommand = cmd


    da.SelectCommand.Parameters.Add(New OleDbParameter("@Methode", CBmethode.Text))         'adding Methode parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Purif", CBpurif.Text))             'adding Purif parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Matrice", CBmatrice.Text))         'adding Matrice parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Molecule", CBmol.Text))            'adding Molecule parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@DatPrepa", DTPechprep.Value))      'adding date parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@datau", DTPechprep.Value))         'adding date parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Trigprep", TBtrigprepa.Text))      'adding Trigprep parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Triganaly", TBtrigAnaly.Text))     'adding Triganaly parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Tech", CBappar.Text))              'adding Tech parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Equip", CBnumappar.Text))          'adding Equip parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@TenMini", TBteneurmini.Text))      'adding TenMini parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@TenMaxi", TBteneurmax.Text))       'adding TenMaxi parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@NomRef", CBnomref.Text))           'adding TenMaxi parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Niv1", CBniv1.Text))               'adding Niv1 parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Niv2", CBniv2.Text))               'adding Niv2 parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Niv3", CBniv3.Text))               'adding Niv3 parameters to datatable
    da.SelectCommand.Parameters.Add(New OleDbParameter("@Niv4", CBniv4.Text))               'adding Niv4 parameters to datatable

    da.Fill(MyDataSet, "Matrice")

    DataGridView1.DataSource = Nothing
    DataGridView1.DataSource = MyDataSet.Tables("Matrice")
    'to focus on first row of DGV after populating it 

    myConnection.Close()

Answers


Normally the problem is the join between tables.

If the relationship is not specified in the right way, this can duplicate rows.

Look that you use the right keys for joining te tables.

In your case, for what i can see, the problem is the table of details, you will have a row for each detail in the table.


Make sure your query is returning unique rows. Try to add a distinct keyword.


Well the problem is so normal because i have duplicated data in a table so the the reaction of Inner Join is normal to duplicate data. I deleted the duplicated data and every thing works well now.


Need Your Help

Why doesn't Google like my PHP script?

php http

I am trying to connect to http://google.com/ and receive their home page with the following code:

Content Negotiation on Tomcat

apache tomcat tomcat6 content-negotiation multiviews

I'm trying to get my Tomcat to use pretty URLs, similar to Apache's MultiViews option. I tried using AJP to proxy Tomcat to Apache, but the .htaccess file is still ignored.